V
Vik
If there are a few Select buttons in a datagrid, is there a way to
distinguish in code which button was clicked?
Thanks.
distinguish in code which button was clicked?
Thanks.
Phillip Williams said:You can use the CommandName parameter of the ButtonColumn control to be
able
to determine the type of action that the user wish to perform on the
record,
e.g.:
<aspataGrid ID="DataGrid1" Runat="server">
<Columns>
<asp:ButtonColumn DataTextField="Field1" CommandName="Select"
ButtonType="PushButton"></asp:ButtonColumn>
<asp:ButtonColumn Text="Delete Row" CommandName="Delete"
ButtonType="PushButton"></asp:ButtonColumn>
<asp:ButtonColumn Text="Duplicate Row" CommandName="Duplicate"
ButtonType="PushButton"></asp:ButtonColumn>
</Columns>
</aspataGrid>
And in handling the ItemCommand event of the datagrid, you would write
code
similar to this:
private void DataGrid1_ItemCommand(object source, DataGridCommandEventArgs
e)
{
switch (e.CommandName.ToString ())
{
case "Select":
//selection code
break;
case "Duplicate":
//do Duplicate code
break;
case "Delete":
//delete code
break;
}
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.