ReadyGo!技术成就梦想 >> 网络编程 >> ASP >> asp中一次更新datagrid中所有记录

asp中一次更新datagrid中所有记录

ReadyGo!技术成就梦想 www.efish.cn efish 2007-10-25 10:47:48
在asp.net中,如何一次性更新datagrid中的所有记录呢?可以用如下的方法,首先,
  要对datagrid中要更新的列建立模版列,比如:

   asp:datagrid id="dgpopularfaqs" runat="server"
  autogeneratecolumns="false"
  ...>
  
    itemstyle-horizontalalign="center" headertext="faq id" />
  
    text="<%# container.dataitem("description") %>" />
  

  
    text="<%# container.dataitem("submittedbyname") %>" />
   
  之后,对datagrid进行一次遍历,
  dim myconnection as new sqlconnection(connection string)
  dim mycommand as new sqlcommand(strsql, myconnection)

  dim dgi as datagriditem
  for each dgi in dgpopularfaqs.items
  "read in the primary key field
  dim id as integer = convert.toint32(dgpopularfaqs.datakeys(dgi.itemindex))
  dim question as string = ctype(dgi.findcontrol("txtdescription"), textbox).text
  dim submittedby as string = ctype(dgi.findcontrol("txtsubmittedby"), textbox).text
  
  "issue an update statement...
  dim updatesql as string = "update tablename set question = @question, " & _
  "submittedbyname = @submittedbyname where faqid = @id"
  mycommand.parameters.clear()
  mycommand.parameters.add("@question", question)
  mycommand.parameters.add("@submittedbyname", submittedby)
  
  mycommand.executenonquery()
  next
 


相关文章
2秒记住本站域名

玩过泡泡龙吗?Readygo?Go! 再加上.Com.Cn的后缀,那就是大名小顶的ReadyGo.com.cn

分类导航
ReadyGo!技术成就梦想