Link: http://dotnet.aspx.cc/article/2cb1c6d7-2b22-4655-8922-2a8a053a66fa/read.aspx
A few days ago, I wrote an example of using the gridview to display the primary table. Some netizens asked how to edit all the data in the detail table at one time? In fact, if you are familiar with ASP. NET or HTML, this batch data editing function is easy to implement. The following example uses a hidden form field to record the ID of the data and append the ID information to the name of each input box. In this way, the data is relatively simple.
The database used in this example is from ASP. NET 2.0 application development technology. Similar to other databases.CodeAnd how to change it.
Aspx:
<xmp> &lt;Br/&gt; &lt;style type = &quot;text/CSS&quot;&gt; TD, Div, A {font-size: 12px} &lt;/style&gt; &lt;p&gt; </xmp>
C #:
Using system; <br/> using system. data; <br/> using system. configuration; <br/> using system. collections; <br/> using system. web; <br/> using system. web. security; <br/> using system. web. ui; <br/> using system. web. UI. webcontrols; <br/> using system. data. oledb; <br/> using system. web. UI. htmlcontrols; <br/> Public partial class default2: system. web. UI. page <br/>{< br/> string connectionstring = @ "provider = Micros Oft. jet. oledb.4.0; Data Source = | datadirectory | \ aspxweb. MDB; persist Security info = true "; <br/> oledbconnection Cn1; <br/> protected void page_load (Object sender, eventargs E) <br/>{< br/> If (! Page. ispostback) <br/>{< br/> oledbconnection Cn = new oledbconnection (connectionstring); <br/> CN. open (); <br/> Cn1 = new oledbconnection (connectionstring); <br/> cn1.open (); <br/> oledbcommand cmd = new oledbcommand ("select * from [subject]", CN); <br/> oledbdatareader DR = cmd. executereader (commandbehavior. closeconnection); <br/> mastergridview. datasource = Dr; <br/> mastergridview. databind (); <br/> dr. c Lose (); <br/> cmd. dispose (); <br/> CN. dispose (); <br/> cn1.dispose (); <br/> Cn = Cn1 = NULL; <br/>}< br/> protected void mastergridview_rowdatabound (Object sender, gridviewroweventargs e) <br/>{< br/> If (E. row. rowtype = datacontrolrowtype. datarow) <br/>{< br/> gridview ogridview = (gridview) E. row. findcontrol ("detailgridview"); <br/> If (ogridview! = NULL) <br/>{< br/> oledbcommand cmd = new oledbcommand ("select top 10 * from document where pid =" + mastergridview. datakeys [E. row. rowindex]. value, Cn1); <br/> oledbdatareader DR1 = cmd. executereader (); <br/> ogridview. datasource = DR1; <br/> ogridview. databind (); <br/> dr1.close (); <br/> cmd. dispose (); <br/>}< br/> protected void detailgridview_rowdeleting (Object sender, gridviewdeletee Ventargs e) <br/>{< br/> gridview A = (gridview) sender; <br/> response. write ("the record you want to delete is:" +. datakeys [E. rowindex]. value. tostring () + "Todo: delete action"); <br/> // todo: delete action <br/>}< br/> protected void detailgridview_rowcommand (Object sender, gridviewcommandeventargs e) <br/>{< br/>}< br/> protected void button#click (Object sender, eventargs E) <br/>{< br/> string guids = request. form ["guid"]; <br/> I F (guids = NULL | guids. Equals (string. Empty) <br/>{< br/> response. Write ("no data can be modified. "); <Br/> return; <br/>}< br/> string SQL; <br/> oledbcommand cmd; <br/> oledbconnection Cn = new oledbconnection (); <br/> CN. connectionstring = connectionstring; <br/> CN. open (); <br/> string [] arrguid = guids. split (','); <br/> for (INT I = 0; I update: Id = "+ arrguid [I] +" "+ request. form ["title" + arrguid [I]. trim ()]); <br/>}< br/> CN. close (); <br/> CN. dispose (); <br/>}</arrguid. length>