i have wrote a simple website with asp and have girdview in it.i want when i click on select in gridview know the index of row(primary key) so i use from girdview.selectedvalue like this in
page load
if (str == "book")
{
//do some works
if(this.IsPostBack)
if (GridView37.SelectedValue != null)
{
Session["Download"] = GridView37.SelectedValue;
}
}
but my problem is that GridView37.SelectedValue
is null forever.what is problem?
What I do is have a method that is called by the OnRowCommand event and within the method do:
public void MyMethod(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
...
}
That gives the index of the row.