Bind nested data for Aspxgridview creation time: November 07, 2011 16:46 Hits: (4619) shared: 4 The previous section provides the binding of nested data in the Aspxgridview. That is, a piece of data that allows the data to be re-bound.
For a very simple example, we use Aspxgridview to show all provinces in China, and then we can bind a subordinate data for each row of data (each province), that is, the information of all municipalities corresponding to each province, and so on, we can also bind all the counties information for each city, and then push the layer level. The specific display on the page is the Aspxgridview on the front of each data has a + number, expand the + number, you can see the subordinate data.
So how do we bind nested data?
You start by setting the showdetailrow=true of the parent Aspxgridview to open the nesting.
<settingsdetail showdetailrow= "true"/>
The child aspxgridview is defined in the <templates ><detailrow > tag of the parent Aspxgridview.
Example: ASP. NET code
<dxwgv:aspxgridview id= "Mastergrid" runat= "Server" Keyfieldname= "Taskcode" clientinstancename= "MasterGrid" Datasourceid= "SqlDataSource1" >
<settingsdetail showdetailrow= "true"/>
<columns >
<dxwgv:gridviewdatacolumn caption= "task number" fieldname= "Taskcode"/>
<dxwgv:gridviewdatacolumn caption= "Task Name" fieldname= "TaskName"/>
<dxwgv:gridviewdatacolumn caption= "task type" fieldname= "TaskType"/>
<dxwgv:gridviewdatacolumn caption= "planned work" fieldname= "planhours"/>
<dxwgv:gridviewdatacolumn caption= "scheduled start time" fieldname= "planbegindate"/>
<dxwgv:gridviewdatacolumn caption= "scheduled end Time" fieldname= "planenddate"/>
<dxwgv:gridviewdatacolumn caption= "Remarks" fieldname= "Remark"/>
</columns >
<templates >
<detailrow >
<dxwgv:aspxgridview id= "Detailgrid" runat= "Server" Keyfieldname= "ID" clientinstancename= "Detailgrid" Datasourceid= "SqlDataSource2"
onbeforeperformdataselect= "Detailgrid_beforeperformdataselect" >
<columns >
<dxwgv:gridviewdatacolumn caption= "id" fieldname= "id"/>
<dxwgv:gridviewdatacolumn caption= "task number" fieldname= "Taskcode" visible= "false"/>
<dxwgv:gridviewdatacolumn caption= "sub-task Name" fieldname= "Childtaskname"/>
<dxwgv:gridviewdatacolumn caption= "Executive person" fieldname= "Executeuser"/>
<dxwgv:gridviewdatacolumn caption= "planned work" fieldname= "planhours"/>
<dxwgv:gridviewdatacolumn caption= "scheduled start time" fieldname= "planbegindate"/>
<dxwgv:gridviewdatacolumn caption= "scheduled end Time" fieldname= "planenddate"/>
</columns >
<settingsdetail isdetailgrid= "true"/>
</dxwgv:aspxgridview >
</detailrow >
</templates >
</dxwgv:aspxgridview >
<asp:sqldatasource
Id= "SqlDataSource1"
runat= "Server"
Datasourcemode= "DataSet"
connectionstring= "Database connection character"
selectcommand= "SQL statement for querying Main table data" >
</asp:sqldatasource >
<asp:sqldatasource
Id= "SqlDataSource2"
runat= "Server"
Datasourcemode= "DataSet"
connectionstring= "Database connection character"
selectcommand= "Querying SQL statements from table data" >
<selectparameters >
<asp:sessionparameter name= "Taskcode" sessionfield= "Taskcode"/>
</selectparameters >
</asp:sqldatasource >
C # code:
Sub-aspxgridview Data binding
protected void Detailgrid_beforeperformdataselect (object sender, EventArgs e)
{
session["Taskcode"] = (sender as Aspxgridview). Getmasterrowkeyvalue ();
}
Note the Detailgrid_beforeperformdataselect method in C # code, which is executed when we expand the data with the DOT + number, and Getmasterrowkeyvalue () is the primary key value in the primary table. Because we set the SessionParameter in SqlDataSource2, we detailgrid_beforeperformdataselect to assign a value to SessionParameter. Source:. NET Learning Network
Note: All the sources for the. NET Learning Network articles are original, if reproduced, please mark this page address in the reprint, thank you! "Edit: Wyf" previous section
Bind nested data for Aspxgridview