Passing the selected gridview row to a new page for edit
Hi , I am a newbee. Please help
I have a gridview displayed in page1
and when a row is selected data on the row should be displayed in page2.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 6, 2009, 9:45 AM EDT
CheckBox1.Text = Session["Discontinued"].ToString();
// if want to Check the Check Box
CheckBox1.Checked = Convert.ToBoolean(Session["Discontinued"]);
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 5, 2009, 8:41 PM EDT
using System; using System.Collections.Generic; using System.Linq; using System.Web; public class DataPassClass { public static string Name ; public static string Age; }Now in Page 1 Write Code In Button1 to pass the Data to that class and We can retrieve content passed to class from page 2
Page 1 Code is Below
You can also Do this Task Without Creating Class File With Session But If you Create Class you can Manage the Code Efficiently.
Deependra Khangarot199 reputationPosted Aug 5, 2009, 9:17 PM EDT
ck blues19 reputationPosted Aug 5, 2009, 9:36 PM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 5, 2009, 9:58 PM EDT
you can do this By Session use Following Code
In Page 1 Write Code as below for example if We are passing two columned Row(Username ,Password)
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { Session["Username"] = GridView1.SelectedRow.Cells[0].Text; Session["Password"] = GridView1.SelectedRow.Cells[1].Text; }In Page 2 Write Code Below to Retrieve Data From Session that We have Stored in Session
protected void Page_Load(object sender, EventArgs e) { Label1.Text = Session["Username"].ToString(); Label2.Text = Session["Password"].ToString(); }Happy Coding :)
ck blues19 reputationPosted Aug 6, 2009, 5:56 AM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 6, 2009, 6:15 AM EDT
Make Sure You have Selected the Row First Then Press Edit and Grid Must Have Some Data like Below Image
Error Says that GridView's Cell[0] contain Null Data ( having No string Value )
You can Check the Grid's Content before Sending it to Session
if your Cell[0] is template field Then let me know other Wise Code is Correct
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { if (GridView1.SelectedRow.Cells[0].Text != null && GridView1.SelectedRow.Cells[1].Text != null) { Session["Username"] = GridView1.SelectedRow.Cells[0].Text; Session["Password"] = GridView1.SelectedRow.Cells[1].Text; } }ck blues19 reputationPosted Aug 6, 2009, 7:11 AM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 6, 2009, 7:32 AM EDT
protected void GridView1_RowEditing1(object sender, GridViewEditEventArgs e) { int index = e.NewEditIndex; Session["Username"] = GridView1.Rows[index].Cells[0].Text; Session["Password"] = GridView1.Rows[index].Cells[1].Text; }Happy Coding :)
ck blues19 reputationPosted Aug 6, 2009, 8:29 AM EDT
ck blues19 reputationPosted Aug 6, 2009, 11:07 AM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 6, 2009, 11:22 AM EDT
then you can Check it at receiving time in page 2
like below
ck blues19 reputationPosted Aug 6, 2009, 1:28 PM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 6, 2009, 5:31 PM EDT
Post your Code of Page 1
and What you have Coded in Page 2 Here
I m not getting you Explain a lil bit what you want to achieve as Final Result .
Happy Coding :)
ck blues19 reputationPosted Aug 6, 2009, 7:05 PM EDT
ck blues19 reputationPosted Aug 6, 2009, 7:07 PM EDT
ck blues19 reputationPosted Aug 6, 2009, 7:12 PM EDT