The nested DataGrid problem is used in the development process:
In a nested DataGrid, how does one call the edit and delete functions (including non-template templates.
==========================================
You can easily edit or delete a template or non-template in a single DataGrid operation. In particular, for a non-template DataGrid, click twice in the attribute builder. the cs file automatically becomes its own code (I feel like playing VB ). However, the DataGrid nested in the DataGrid or DataList does not have such an operation method. You must add the compile code on your own.
Paste the process of exploration to everyone!
----------------------------
Master DataGrid name: dgM
Nested Datagrid name: dgD
We can generate a function when we drag dgM into the interface:
Private void InitializeComponent ()
{
This. dgM. ItemDataBound + = new System. Web. UI. WebControls. DataGridItemEventHandler (this. dgM_ItemDataBound );
This. Load + = new System. EventHandler (this. Page_Load );
}
The green field above is automatically generated by VS.net. However, VS.net does not have such a generation method in nested dgD. You can only add them manually. However, you should not add the distinct method in the dgM_ItemDataBound method (here there is a misunderstanding, so I am stuck in this misunderstanding For A Long Time). You should add it in the dgM_ItemCreated method. For example:
Private void dgM_ItemCreated (object sender, System. Web. UI. WebControls. DataGridItemEventArgs e)
{
If (e. Item. ItemType = ListItemType. Item | e. Item. ItemType = ListItemType. AlternatingItem)
{
DgDList = (DataGrid) e. Item. FindControl ("dgD ");
DgDList. ItemDataBound + = new System. Web. UI. WebControls. DataGridItemEventHandler (this. dgD_ItemDataBound );
DgDList. ItemCommand + = new System. Web. UI. WebControls. DataGridCommandEventHandler (this. dgD_ItemCommand );
}
}
If the preceding green code is added to the dgM_ItemDataBound method, commands such as dgD_ItemCommand cannot be called.
Now you can add the sequence and operation methods of dgD, such:
Private void dgD_ItemCommand (object source, System. Web. UI. WebControls. DataGridCommandEventArgs e)
{
//.......
}
---------------------------------------------------
In addition, the Code debugging result is as follows:
If you add the following content to PageLoad ():
If (! This. Page. IsPostBack)
{
This. BindData ();
}
After such code is used, when editing or deleting operations (that is, the server control) are used in the DataGrid, The DataGrid is no longer set, that is, the DataGrid will no longer execute the _ ItemDataBound method. However, the _ ItemCreated method is executed. This is why the code is not stored in the _ ItemDataBound method.