How can i select row in gridview by clicking. But i want to add select id (from database such as primary id) in session. Listen please i dont want javascript Attribute method. Like that
session["selectedrow"] = gridview1.selectedrow[" which id? "]
How can i select row in gridview by clicking. But i want to add select id (from database such as primary id) in session. Listen please i dont want javascript Attribute method. Like that
session["selectedrow"] = gridview1.selectedrow[" which id? "]
protected void Unnamed1_SelectedIndexChanged(object sender, EventArgs e)
{
Session["key"] = ((GridView)sender).SelectedDataKey.Value;
}
<asp:GridView ID="Unnamed1" runat="server"
onselectedindexchanged="Unnamed1_SelectedIndexChanged" ></asp:GridView>
Untested, but I don't see why this wouldn't work.
Setup the data key like this:
grdTestData.DataSource = GetDataTable();
grdTestData.DataKeyNames = new string[] { "Dataset_ID" };
grdTestData.DataBind();
Get the key (from a command button):
int iRow = Convert.ToInt32(e.CommandArgument);
Session["key"] = grdTestData.DataKeys[iRow]