-1

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?

4

2 回答 2

0

如果不发布您的错误,就很难看出问题所在。您可以检查您的应用程序中是否启用了会话。

另一种方法(可能更好)是仅将 id/slno(通过 QueryString)传递到您的其他页面,然后在该阶段执行查找以获取您的数据。

于 2012-10-12T11:05:30.050 回答
0

我一定会为预订创建一个类型(类)

具有 slno title author publication属性和

public class Booking
{
    public Booking()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    public int slno { get; set; }
    public string Title { get; set; }
    public string author { get; set; }
    public string publication { get; set; }

}

设置预订类型对象的所有属性并在会话中传递该对象

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string user = (string)(Session["User"]);
        if (e.CommandName.Equals("SendRequestCmd"))
        {
            if (user == null)
            {
                Booking b = new Booking();
                b.slno = clickedRow.Cells[0].Text;
                b.Title = BookName.ToString();

                Session["Booing"] = b;

            }
        }
    }

并且在接收端,只需将该会话值再次放入该对象中,并通过使用带有对象名称的点来访问每个属性。

   Booking b=(Booking)Session["Booking"]
       int slno=b.slno;
    string Title=b.Title;

如果不发布错误就不可能给出建议或更正,我的回答是如何使用会话将多个值从一个页面传递到另一个页面。

谢谢

于 2012-10-12T11:08:55.730 回答