Nested gridview in ASP. NET gridview

Source: Internet
Author: User
// ASPX page <asp: gridview id = "gridview2" runat = "server" autogeneratecolumns = "false" gridlines = "NONE" showheader = "false" onrowdatabound = "gridview2_rowdatabound"> <columns> <asp: templatefield> <itemtemplate> <asp: gridview id = "gridview1" runat = "server" autogeneratecolumns = "true"> </ASP: gridview> </itemtemplate> </ASP: templatefield> </columns> </ASP: gridview> // Aspx. CS page protected void gridview2_rowdatabound (Object sender, gridviewroweventargs e) {If (E. row. rowtype = datacontrolrowtype. datarow) {gridview GRD = E. row. cells [0]. findcontrol ("gridview1") as gridview; GRD. datasource = dataset; GRD. databind ();}} **************************************** * ************************* gridview nested gridview ++. aspx Code ++ Onrowdatabound event, which has a leg with itemdatabound in 1.x. <! -- The first layer of the gridview starts --> <asp: gridview id = "gridview1" onrowdatabound = "gridview1_rowdatabound" autogeneratecolumns = false runat = "server"> <columns> <asp: templatefield> <itemtemplate> <% # container. dataitem. tostring () %> <! -- Level 2 gridview start --> <asp: gridview id = "gridview2" onrowdatabound = "gridview2_rowdatabound" autogeneratecolumns = false runat = "server"> <columns> <asp: templatefield> <itemtemplate> <% # container. dataitem. tostring () %> <! -- The third-layer gridview starts --> <asp: gridview id = "gridview3" autogeneratecolumns = false runat = Server> <columns> <asp: templatefield> <itemtemplate> <% # container. dataitem. tostring () %> </itemtemplate> </ASP: templatefield> </columns> </ASP: gridview> <! -- End the third-level gridview --> </itemtemplate> </ASP: templatefield> </columns> </ASP: gridview> <! -- The second layer of the gridview ends --> </itemtemplate> </ASP: templatefield> </columns> </ASP: gridview> <! -- The first layer of the gridview ends --> ++. CS code ++ rowdatabound and 1. itemdatabound in X also has a leg! Using system; using system. data; using system. configuration; using system. web; using system. web. security; using system. web. ui; using system. web. UI. webcontrols; using system. web. UI. webcontrols. webparts; using system. web. UI. htmlcontrols; using system. collections; public partial class _ default: system. web. UI. page {protected void page_load (Object sender, eventargs e) {This. gridview1.datasource = Al ("gridview1item:"); this. gridview1.databind ();} // datasource protected arraylist Al (string getstr) {arraylist Al = new arraylist (); For (INT I = 0; I <2; I ++) {Al. add (getstr + I. tostring ();} return Al;} // gridview1_rowdatabound protected void gridview1_rowdatabound (Object sender, gridviewroweventargs e) {If (E. row. rowtype = datacontrolrowtype. datarow) {gridview GV = (gridview) E. row. findcontrol ("gridview2"); GV. datasource = Al ("gridview2item:"); GV. databind () ;}}// gridview2_rowdatabound protected void gridview2_rowdatabound (Object sender, gridviewroweventargs e) {If (E. row. rowtype = datacontrolrowtype. datarow) {gridview GV = (gridview) E. row. findcontrol ("gridview3"); GV. datasource = Al ("gridview3item:"); GV. databind ();}}}

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.