I have a GridView on a .aspx page with a hidden column which has an ID value. When the user clicks on a certain row, I need the ID column value on the C# code behind, so that I can query the database and populate another view with data corresponding to this ID. My problem is, I can pass this ID value to a javascript function in the onClick event of the row, but how do I get it to the code behind from where I can actually query the SQL Server database?
Share
This is how I solved it –
Got the selected row index with –
e.Row.Attributes[“onclick”] = ClientScript.GetPostBackClientHyperlink(this.GridView2, “Select$” + e.Row.RowIndex);
In the SelectedIndexChanged event of the Grid –
GridView2.SelectedRowStyle.BackColor = System.Drawing.Color.LightGray;
string id = GridView2.SelectedRow.Cells[0].Text;
Where, Cells[0] was my hidden column which contains the ID value