Link to home
Create AccountLog in
Avatar of asudhaa
asudhaa

asked on

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

Avatar of Paul MacDonald
Paul MacDonald
Flag of United States of America image

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.
ASKER CERTIFIED SOLUTION
Avatar of Imran Javed Zia
Imran Javed Zia
Flag of Pakistan image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer