How to pass the checkbox list value from one page to another


hi,
 I have a checkboxlist ,which has its databound from SQL dabase.I am using this checkboxlist in administrator page.So that when a checkbox in the checkboxlist is clicked I would like to pass this value to another page in which I enable a function(For example I enable a Button if the checkboxlist is checked else the button is disabled).
  I tried to pass this value(the checkboxlist selected value) using a session but I dont know how to do this exactly as I am new to ASP.net and C#.
 I am trying with the code below .Can you help me how I can achieve this




The code in the Administrator page
code in aspx.cs 

 protected void Page_Load(object sender, EventArgs e)
        {           
                if (Session["Sel_Inst"] != null)
                    Label2.Text = Session["Sel_Inst"].ToString();
         }

 protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Label1.Text = string.Empty;
            foreach (ListItem listitem in CheckBoxList1.Items) { 
                if (listitem.Selected) 
                    Label1.Text += listitem.Value + "<br />";
            }
            Session["Sel_Inst"] = Convert.ToString(Label1.Text);
        }


code in aspx 

<asp:CheckBoxList 
            ID="CheckBoxList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" 
            DataTextField="Institution_name" DataValueField="Institution_no" 
            onselectedindexchanged="CheckBoxList1_SelectedIndexChanged" >
        </asp:CheckBoxList>

Open in new window



The code in the page where I would like to pass the value from the Administrator page

 protected void Page_Load(object sender, EventArgs e)
        {
            string En_Resub;
            if (Session["Sel_Inst"] != null)
             En_Resub = Session["Sel_Inst"].ToString();
        }

Open in new window

asudhaaAsked:
Who is Participating?
 
Imran Javed ZiaConsultant Software Engineer - .NET ArchitectCommented:
Hi,
you can use a hiddenfield and with Postbackurl feature with PreviousPage, or you can also use querystring

for more details refer to
http://www.dotnetheaven.com/UploadFile/prathore/PostBack05032007005048AM/PostBack.aspx
0
 
Paul MacDonaldDirector, Information SystemsCommented:
Hmm.  I think your best approach would be to commit the data back to the SQL database, then use the committed values to dis/enable the buttons on the second page.

If you don't want to do that, you can store the checkbox values (both checked and unchecked) in an array, stuff that into your session variable, then parse the array on the second page to dis/enable the buttons.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.