How to get the command name of a control
-
hi everybody, it seems that i have a biiig problem, and i'm counting on you to resolve it... pls :) well, i want to get the name of a button's command in a datagrid. here is the code that i've made: void DataGrid1_ItemCommand(object source, DataGridCommandEventArgs e) { if(e.CommandName=="Editer") { int id; LinkButton tb_id=(LinkButton)e.Item.Cells[6].Controls[0]; id=Convert.ToInt32(tb_id.Text); Response.Redirect("FicheModulesTech.aspx?id_cours="+id); } } the command name is "Editer", and it doesn't work!!! anyone can help??? thanks
-
hi everybody, it seems that i have a biiig problem, and i'm counting on you to resolve it... pls :) well, i want to get the name of a button's command in a datagrid. here is the code that i've made: void DataGrid1_ItemCommand(object source, DataGridCommandEventArgs e) { if(e.CommandName=="Editer") { int id; LinkButton tb_id=(LinkButton)e.Item.Cells[6].Controls[0]; id=Convert.ToInt32(tb_id.Text); Response.Redirect("FicheModulesTech.aspx?id_cours="+id); } } the command name is "Editer", and it doesn't work!!! anyone can help??? thanks
Hi there, In most cases, the words "it doesn't work" do not help people much in figuring out the cause of an issue. Do you mean the execution does not get in the body of the if statement or you cannot access the id value? Is the
Editer
is the CommandName of the LinkButton? Here, from what your sample code I guess that you want to get the id_cours value and redirect to another way, if so you might to try theHyperLinkColumn
or theHyperLink
control instead of the LinkButton. -
hi everybody, it seems that i have a biiig problem, and i'm counting on you to resolve it... pls :) well, i want to get the name of a button's command in a datagrid. here is the code that i've made: void DataGrid1_ItemCommand(object source, DataGridCommandEventArgs e) { if(e.CommandName=="Editer") { int id; LinkButton tb_id=(LinkButton)e.Item.Cells[6].Controls[0]; id=Convert.ToInt32(tb_id.Text); Response.Redirect("FicheModulesTech.aspx?id_cours="+id); } } the command name is "Editer", and it doesn't work!!! anyone can help??? thanks
Hi, Use the following code: LinkButton lb = (LinkButton)DataGrid1.Items[e.Item.ItemIndex].Controls[2].Controls[0]; I posted some tutorials on how to customize the DataGrid control at www.KYNOU.com. There is also a chat room there and I try to be there as long as I can. If you have any question please stop by and I will be glad to try to help you. :)
-
Hi, Use the following code: LinkButton lb = (LinkButton)DataGrid1.Items[e.Item.ItemIndex].Controls[2].Controls[0]; I posted some tutorials on how to customize the DataGrid control at www.KYNOU.com. There is also a chat room there and I try to be there as long as I can. If you have any question please stop by and I will be glad to try to help you. :)