我想在登錄頁面設置會話,並希望將一個頁面girdview數據傳遞到另一個頁面。傳遞gridview特定的行數據到asp.net中的另一個頁面?
slno title author publication takenby
1 book1 author1 pub1 sendrequest (button)
上圖顯示gridview。當我點擊請求書按鈕(第一個)。它會重定向到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"]);
爲什麼?有人糾正它? 別的說更好的方法?
您收到的會話對象的錯誤是什麼? – martinwnet
而不是在分隔會話中傳遞每個值只需創建一個類型(Class)並將每個值作爲屬性並設置對象的每個屬性,並在會話中傳遞該對象並將其轉換爲接收結束,便於檢查會話對於單個會話爲空4-5個會話值 – rahularyansharma