I am adding a new functionality to an old system, I need to add a new LinkButton to a GridView. How can I know which LinkButton was clicked so that I can do different things. Right now they are, of course, doing the same thing.
<asp:GridView ID="gvHabitacionesCD" runat="server" CssClass="datatable"
AutoGenerateColumns="False" Width="100%"
OnSelectedIndexChanged="gv_SelectedIndexChanged"
EmptyDataText="Select a Period"
DataKeyNames="idH">
<Columns>
<asp:BoundField HeaderText="idH" DataField="idH" Visible="false" />
<asp:TemplateField HeaderText="Last Name">
<ItemTemplate>
<asp:LinkButton ID="btnSelectLastName" runat="server" CommandName="Select" Text='<%# Eval("LastName") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:LinkButton ID="btnSelectName" runat="server" CommandName="Select" Text='<%# Eval("Name") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
On CodeBehind
protected void gv_SelectedIndexChanged(object sender, EventArgs e)
{
GridView gv = (GridView)(sender);
getReservation(gv.DataKeys[gv.SelectedIndex].Value.ToString());
}
CommandNamespersonally and add your own command handling (i.e. GridView RowCommand), so you could have a commandSelectFirstNameand thenSelectLastName- JohnPete22senderobject to identify the button. docs.microsoft.com/en-us/dotnet/api/… - JohnPete22