How to pass checkbox data from one page to another

2019-09-05 16:51发布

问题:

I am trying to pass data from one page to another using asp.net

I wrote this code in the second page

protected void Page_Load(object sender, EventArgs e)
{  
    Div1.InnerHtml = "I am here";

    if (Page.PreviousPage != null)
    {
        CheckBoxList CheckBoxList1 = 
            (CheckBoxList)PreviousPage.FindControl("CheckBoxList1");

        string section = "";

        foreach (ListItem sec in CheckBoxList1.Items)
        {
            if (sec.Selected)
            {
                section += sec.Text + "<br />";
                this.d.InnerHtml = section;
            }
        }
    }
}

but it does not work :(

Please help me to find the error :)

回答1:

Save the checkbox values from the first page in session variables or cookies, from where they can be retrieved later in the second page.