GridView to DetailsView (on a different page), passing of variable
-
Hi, I'm trying to get the key of the GridView into the DetailsView and using Session doesn't seem to work. The GridView (Parent page) has summaries of the data. I'm using a to get the ID and redirect to the DetailsView page (Child page). 2 different pages. What I'm currently doing is this protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { Session["ID"] = GridView1.Rows[0].ToString(); Response.Redirect("DetailsPage.aspx"); } And the DetailsPage has this for getting the parameter I know the problem is that the data types are incompatible but how can I cast the data? Or is the problem more than that. If this is the wrong way, how can I pass the ID from the parent to the child (different pages)? And I don't want to put the data in the URL. Thanks. Desmond
-
Hi, I'm trying to get the key of the GridView into the DetailsView and using Session doesn't seem to work. The GridView (Parent page) has summaries of the data. I'm using a to get the ID and redirect to the DetailsView page (Child page). 2 different pages. What I'm currently doing is this protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { Session["ID"] = GridView1.Rows[0].ToString(); Response.Redirect("DetailsPage.aspx"); } And the DetailsPage has this for getting the parameter I know the problem is that the data types are incompatible but how can I cast the data? Or is the problem more than that. If this is the wrong way, how can I pass the ID from the parent to the child (different pages)? And I don't want to put the data in the URL. Thanks. Desmond
Desmond Lim wrote:
Session["ID"] = GridView1.Rows[0].ToString();
Its seems like you are not getting values from any of the cells in the GridView. Mostly your Session object would have the text of the data type of GridViewRow like "System.Web....GridViewRow". try like,
Session["ID"] = GridView1.Rows[0].Cell[cellIndex].Text;
orSession["ID"] = Convert.ToInt32(GridView1.Rows[0].Cell[cellIndex].Text);
where cellIndex is the index of the gridview's column[Venkatesh Mookkan] My: Website | Yahoo Group | Blog Spot
-
Desmond Lim wrote:
Session["ID"] = GridView1.Rows[0].ToString();
Its seems like you are not getting values from any of the cells in the GridView. Mostly your Session object would have the text of the data type of GridViewRow like "System.Web....GridViewRow". try like,
Session["ID"] = GridView1.Rows[0].Cell[cellIndex].Text;
orSession["ID"] = Convert.ToInt32(GridView1.Rows[0].Cell[cellIndex].Text);
where cellIndex is the index of the gridview's column[Venkatesh Mookkan] My: Website | Yahoo Group | Blog Spot
Thanks Venkatesh