ASP. NET 2.0-how to nest the gridview Control
Chart1
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.
Chart2
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 ).