This is a migrated thread and some comments may be shown as answers.

RADCombo Box with CheckBox

3 Answers 98 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sushobhit
Top achievements
Rank 2
Sushobhit asked on 20 Jul 2012, 10:32 AM
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

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 22 Jul 2012, 07:28 PM
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
0
Princy
Top achievements
Rank 2
answered on 23 Jul 2012, 12:46 PM
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.
0
Sushobhit
Top achievements
Rank 2
answered on 24 Jul 2012, 12:50 PM
thanks all i have solve this problem .
Tags
General Discussions
Asked by
Sushobhit
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Sushobhit
Top achievements
Rank 2
Share this question
or