In asp.net, how do I update all the records in the DataGrid at once? You can use the following method, first of all,
To create a template column for the column you want to update in the DataGrid, for example:
Asp:datagrid id= "Dgpopularfaqs" runat= "Server"
autogeneratecolumns= "False"
...
itemstyle-horizontalalign= "Center" headertext= "FAQ ID"/> "!--? xml:namespace prefi x = ASP/-->
text= ' <%# container.dataitem (" Description ")%> '/>
text= ' <%# container.dataitem ("Submittedbyname")%> '/>
, the DataGrid For one traversal,
Dim myconnection As New SqlConnection (connection string)
Dim mycommand as new SqlCommand (s Trsql, 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