I have an ASP.NET GridView
control with two asp:CommandField
columns that are both using the Select command to perform different tasks. How do I distinguish which column was selected in the OnRowCommand
event when both return "Select" when I check the CommandName
property of the GridViewCommandEventArgs
object?
Here is my source code:
ASPX page:
<asp:GridView ID="MyGridView" runat="server" AutoGenerateColumns="false" OnRowCommand="MyGridView_OnRowCommand">
<Columns>
<asp:CommandField ButtonType="Link" ShowSelectButton="true" SelectText="Click Me!" />
<asp:CommandField ButtonType="Link" ShowSelectButton="true" SelectText="No Click Me!" />
</Columns>
</asp:GridView>
Code behind:
protected void MyGridView_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
string x = e.CommandName //returns "Select" for both asp:CommandField columns
}