ASP. NET 2.0-how to nest the gridview control from cnblogs)

Source: Internet
Author: User
ASP. NET 2.0-how to nest the gridview Control



I recently heard from many friends asking how to use it in nest mode.GridviewControl, that is, inGridviewControl contains anotherGridviewControl. We are writingASP. NET AjaxAt the time of writing this book, I just wrote an example to share with you the key skills.


Chart1As shown in the following figure, we use a nest-like web page.GridviewControl. OuterGridviewControls are used to display product category data (that is, parent data records ),GridviewControls are used to display products of a specific category (that is, sub-data records ). How can I create such an interface? The key skills are described as follows:


QFirst, you must replaceGridviewControl to add a sample data row (that isTemplatefield), And addGridviewControls (Tables2), Which is located in the sample data row.GridviewControl will become the innerGridviewControl.




Q write the following for the rowdatabound event processing routine of the outer gridview control:ProgramCodeTo assign the category Id field value of the outer product category data column to the select declarative categoryid parameter of the data source of the inner gridview control. As a result, the inner gridview control displays the product data associated with the product category data column:

Protected sub productcategorygridview_rowdatabound (_
Byval sender as object ,_
Byval e as system. Web. UI. webcontrols. gridviewroweventargs )_
Handles productcategorygridview. rowdatabound
If E. Row. rowtype = datacontrolrowtype. datarow then
Dim s as sqldatasource = _
Ctype (E. Row. findcontrol ("productsdatasource"), sqldatasource)
Dim R as system. Data. datarowview = _
Ctype (E. Row. dataitem, system. Data. datarowview)
S. selectparameters ("categoryid"). defaultvalue = R ("category No."). tostring ()
End if

End sub


This article is recorded in 「ASP. NET AjaxBig decryption book "(tentative title ).

Related Article

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: 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.