How can I store data in a variable on client click within a grid view?
I have a Stored Procedure that returns Service Id based on the Department code provided. We are binding these details to a Grid View. How can we bind the Service Id to a variable that can be accessed throughout the code and passed to different Stored Procedures? Currently, I am hard coding test data for this purpose. While binding to the grid view, we are not displaying the Service Id anywhere but it is present in the data table. I am using RowDataBound but struggling to store the clicked element in a variable.
C# part
protected void gvServiceCount_RowDataBound(object sender, GridViewRowEventArgs e)
{ int serviceId = Convert.ToInt32(e.Row.Cells[2].Text);
Session["serviceId"] = serviceId;
}
ASP.NET part
<asp:GridView ID="gvServiceCount" runat="server" AutoGenerateColumns="false" EmptyDataText="No Data Found"
Width="100%" HeaderStyle-BackColor="#facf5a" OnSelectedIndexChanged="gvServiceCount_SelectedIndexChanged" OnRowDataBound="gvServiceCount_RowDataBound"
HeaderStyle-ForeColor="Black" RowStyle-BackColor="White"
RowStyle-ForeColor="Black">
<Columns>
<asp:TemplateField HeaderText="Closed">
<ItemTemplate>
<asp:LinkButton ID="lblClosedCount" Text='<%#Eval("SUMOFAPPROVEREJECTED") %>' runat="server" OnClick="lblClosedCount_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I need to find a way to store the data in a variable upon client click.