DataGrid template column Operation Problems

Source: Internet
Author: User

 

Thanks for posting in this group.
I think maybe you bind the database data into your DataGrid every time in
Webform load event.
Because when you click the button, the page PostBack to the server,
Page_load event fires, the DataGrid will be rebind again. So
Itemcommand will not fire (the DataGrid was reinitialized). (You can
Demonstrate this through Add a breakpoint in itemcommand eventhandler)
So you shoshould bind the DataGrid only when the page is not PostBack.
Code snippet like this:

// I use default sqlserver database to fill the DataGrid
Private void page_load (Object sender, system. eventargs E)
{
// Put user code to initialize the page here
// Response. Write (session [0]);
Response. Write (this. getpostbackeventreference (Hoho ));
If (! Ispostback)
{
Sqldataadapter adapter = new sqldataadapter ("select * from
Jobs "," Server = localhost; database = pubs; uid = sa; Pwd = ");
Dataset DS = new dataset ();
Adapter. Fill (DS );
Datagrid1.datasource = Ds;
Datagrid1.databind ();
}
}

This. datagrid1.itemcommand + = new
System. Web. UI. webcontrols. Maid (this. Maid itemcom
Mand );

Private void datagrid1_itemcommand (Object source,
System. Web. UI. webcontrols. datagridcommandeventargs E)
{
If (E. commandname = "buttonclick ")
{
Response. Write (E. Item. cells [3]. Text );
}
}

Best regards,
Jeffrey Tan
Microsoft online partner support
Get secure! -Www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights

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.