[ASP.net] DataGrid nested DataGrid

Source: Internet
Author: User
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.

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