How can get the event of a button added in a datagrid in asp.net?
-
Hai, I have added button using property builder in datagrid. I want to execute some functions under this button click.How I can get the server side events of that button.How I can do this? Please show me the right way. Thank You, Rahul.P.Menon.
-
Hai, I have added button using property builder in datagrid. I want to execute some functions under this button click.How I can get the server side events of that button.How I can do this? Please show me the right way. Thank You, Rahul.P.Menon.
-
a. use ItemDataBound_DataGrid Event b. find the control Dim btn AS Button = CType(e.Item.FindControl("Buttonname"),Button) C. add your event
Hai Satheesh, Thanks much for your reply. Rahul.P.Menon
-
Hai, I have added button using property builder in datagrid. I want to execute some functions under this button click.How I can get the server side events of that button.How I can do this? Please show me the right way. Thank You, Rahul.P.Menon.
I'll add a different approach to sathish's answer - Since you are adding the button in a datagrid column, you can take advantage of event bubbling within the datagrid. Assign a
CommandName
(and optionallyCommandArgument
to the button (these are properties of the button). Then in the code handler for the DataGrid'sItemCommand
event, you can determine if that command button were clicked by it'sCommandName
. For example, if you named your button "Details", then your DataGrid ItemCommand handler might look like this:void MyGrid_ItemCommand(object o, DataGridCommandEventArgs e)
{
if (e.CommandName == "Details")
{
// do something when "Details" is clicked...
// perhaps check e.CommandArgument to get to additional
// data assigned to the button...
}
}It's typical to use a
switch
statement in an ItemCommand handler if you have several buttons with CommandName's in your datagrid. -
Hai, I have added button using property builder in datagrid. I want to execute some functions under this button click.How I can get the server side events of that button.How I can do this? Please show me the right way. Thank You, Rahul.P.Menon.
Hi Try this: int tmpid = Convert.ToInt32(datagrid.DataKeys[(int)e.Item.ItemIndex]); string popupScript = "< Script language = 'javascript'>"+ string.Format("javaScript:window.opener.document.{0}.value = \'{1:d}\';window.close(0;", request.QueryString["field"], Convert.ToInt32(tmpid)) + ""; Page.RegisterClientScriptBlock("PopupScript",popupScript); In Properties of DataGrid, This Code as to be written in "ItemCommand" Event. Regards, Naren please help me