i want to set session in login page and want to pass one page girdview data to another page.
slno title author publication takenby
1 book1 author1 pub1 sendrequest (button)
Above image showing gridview. when i click the Request Book button(1st one). it will redirect to sendrequest.aspx page. and have to bring that row data (i.e)
slno=1
title=book1
Author=author1
publication=publ
i tried below code user.aspx.cs
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
string user = (string)(Session["User"]);
if (e.CommandName.Equals("SendRequestCmd"))
{
if (user == null)
{
Session["slno"] = null;
Session["bookname"] = null;
var clickedRow = ((Button)e.CommandSource).NamingContainer as GridViewRow;
// now access the cells like this
SlNo = clickedRow.Cells[0].Text;
Session["slno"] = SlNo.ToString();
BookName = clickedRow.Cells[1].Text;
Session["bookname"] = BookName.ToString();
}
}
}
sendquest.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
string slno = "", bookname = "";
slno = (string)(Session["slno"]);
bookname = (string)(Session["bookname"]);
if (slno == null || bookname == null)
{
Response.Write("serial no: " + slno + "\nbookname: " + bookname);
}
}
protected void Logout()
{
Session.Clear();
}
but i got error in
slno=(string)(Session["slno"]);
bookname=(string)(Session["bookname"]);
why? anybody correct it? else say better way?