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