ログインページでセッションを設定し、あるページのグリッドビューデータを別のページに渡したい。
slno title author publication takenby
1 book1 author1 pub1 sendrequest (button)
グリッドビューを示す上の画像。[ブックのリクエスト]ボタン(最初のボタン)をクリックしたとき。sendrequest.aspxページにリダイレクトされます。その行データを持ってくる必要があります(すなわち)
slno=1
title=book1
Author=author1
publication=publ
私は以下のコード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();
}
しかし、私はエラーが発生しました
slno=(string)(Session["slno"]);
bookname=(string)(Session["bookname"]);
なぜ?誰かがそれを修正しますか?他にもっと良い方法を言いますか?