RADCombo Box with CheckBox

4 posts, 0 answers
  1. Sushobhit
    Sushobhit avatar
    26 posts
    Member since:
    Apr 2011

    Posted 20 Jul 2012 Link to this post

    Hi All 


    I have a drop down with check box. user can select the more then one value select in check box and this value can save in the session variable after that redirect to the next page when user come back again in this page all selected check box value    those are saved in the session can set the all the check box value  checked in that drop down.

    for example user can select 2 value then session["selectedvalue"]="1,2";
    then how to set this selected value set in the check box of that combo box. 




    thanks 

    Sushobhit Raman
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 22 Jul 2012 Link to this post

    Hello,

    Session["selectedvalue"] = "1,2";
               if (Session["selectedvalue"] != null)
               {
                   string[] strarry = Session["selectedvalue"].ToString().Split(',');
                   foreach (string str in strarry)
                   {
                       if (RadComboBox1.Items.FindItemByValue(str) != null)
                       {
                           RadComboBox1.Items.FindItemByValue(str).Checked = true;
                       }
                   }
               }


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Jul 2012 Link to this post

    Hi Sushobhit,

    You can keep track of checked items as a boolean array in the session. Here is the sample code.

    ASPX:
    <telerik:RadComboBox ID="RadComboBox1" runat="server" CheckBoxes="true" AutoPostBack="true" onitemchecked="RadComboBox1_ItemChecked" >
     <Items>
      ................
     </Items>
    </telerik:RadComboBox>

    C#:
    static Boolean[] state = new Boolean[10];
    protected void Page_Load(object sender, EventArgs e)
     {
      if (!IsPostBack)
      {      
       if (Session["state"] == null)
       {
        for (int i = 0; i < RadComboBox1.Items.Count; i++)
        {
         state[i] = false;
        }
        Session["state"] = state;
       }
       else
       {
        state = (Boolean[])Session["state"];
        for (int i = 0; i < RadComboBox1.Items.Count; i++)
        {
         RadComboBox1.Items[i].Checked = state[i];
        }
       }
      }
     }
     protected void RadComboBox1_ItemChecked(object sender, Telerik.Web.UI.RadComboBoxItemEventArgs e)
     {
      state[e.Item.Index] = e.Item.Checked;
      Session["state"] = state;
     }

    Thanks,
    Princy.
  5. Sushobhit
    Sushobhit avatar
    26 posts
    Member since:
    Apr 2011

    Posted 24 Jul 2012 Link to this post

    thanks all i have solve this problem .
Back to Top