An example of using the gridview to display the primary table and edit all data in the detail table at a time

Source: Internet
Author: User

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> <Br/> <style type = "text/CSS"> TD, Div, A {font-size: 12px} </style> <p> </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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.