1
Reply

how to handle multiple link button event in gridview

Harshal Kulkarni

Harshal Kulkarni

Jan 24 2017 12:33 AM
573
Hello everyone, i have multiple link buttons in gridview and have to write event for selected link button. All buttons are fire different query and output will be send on another page. 
 
 This is my HTML code:
 
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" CssClass="Grid" ondatabound="GridView1_DataBound"
onrowcreated="GridView1_RowCreated" onrowdatabound="GridView1_RowDataBound"
onselectedindexchanged="GridView1_SelectedIndexChanged" Width="152px"
onrowcommand="GridView1_RowCommand">

<Columns>
<asp:BoundField runat="server" DataField="LOSS" HeaderText="Loss Range" />
<asp:TemplateField HeaderText="sd">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="sd" >LinkButton</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="scd">
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="scd">LinkButton</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="cd">
<ItemTemplate>
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="cd">LinkButton</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="nd">
<ItemTemplate>
<asp:LinkButton ID="LinkButton4" runat="server" CommandName="nd">LinkButton</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ed">
<ItemTemplate>
<asp:LinkButton ID="LinkButton5" runat="server" CommandName="ed">LinkButton</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
 C# Code:
 
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "sd")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[index];
if (row.Cells[1].Text != " ")
{
e.Row.Cells[1].Attributes.Add("onClick", "openWindow_Requests('" + division + "," + category + "," + month + "," + year + "')");
}
}
 
 
 
Thanks in advanced. 
 
 

Answers (1)