Passing Gridview Values to Session
Hi,
I need some serious help with this one. I have a gridview and it finds all the records associated with a given user, i want to extract one cell(QueryID) to session and have a gridview reference this session variable in another page. I have no code in the second page and very little in the first page. Does anyone have any ideas on where i can get started? thanks in advance
protected void Page_Load(object sender, EventArgs e)
{
string username = Session["UserName"].ToString();
TextBox1.Text = username;
}
protected void CloseButton_Click(object sender, EventArgs e)
{
}
protected void MessageButton_Click(object sender, EventArgs e)
{
Response.Redirect("AddMessage.aspx");
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
Session["QueryID"] = GridView1.SelectedRow.Cells[0];
}
Master BillaPosted Nov 10, 2009, 9:26 PM
here is complete way
Main Page
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Page_Load(object sender, EventArgs e)
{
string username = Session["UserName"].ToString(); TextBox1.Text = username;
}
protected void CloseButton_Click(object sender, EventArgs e)
{
}
protected void MessageButton_Click(object sender, EventArgs e)
{
Response.Redirect("AddMessage.aspx");
}
GridView GridView1;
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (GridView1.SelectedRow != null)
{
Session["QueryID"] = GridView1.SelectedRow.Cells[0].Text;
Response.Redirect("SecondPage.aspx");
}
}
}
Detail Page
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Detail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["QueryID"] != null)
{
string id = Session["QueryID"].ToString();
// do the necessary function call here to load detail records;
}
}
}
thank you