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

Rebind ComboBox with multiple checked check boxes

1 Answer 126 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 06 May 2012, 02:33 PM
Hi

I'm using a RadComboBox with check boxes and server side when the user saves the form I insert using the following:
var sb = new StringBuilder();
var collection = ddlAdditionalStaff.CheckedItems;
foreach (var item in collection)
sb.Append(item.Value + "|");

Which leaves me with a field in my database table eg. Fred|Mark|Gary|

My question is how can I rebind this field to the RadComboBox with Checkboxes when the user edits the form. I have tried the text, selected value and checkeditems without luck. I have seen in the documentation the DataCheckedField can be used, but I do not understand it's use so could do with some clarification.

Any help would be greatly appreciated.

Ben

1 Answer, 1 is accepted

Sort by
0
Ben
Top achievements
Rank 1
answered on 07 May 2012, 03:20 PM
Answered my own question..

protected void FormView1_DataBound(object sender, EventArgs e)
{
    if (FormView1.DataItem != null)
    {
        RadComboBox ddlAdditionalStaff = FormView1.FindControl("ddlAdditionalStaff") as RadComboBox;
        if (ddlAdditionalStaff != null)
        {
            string csv = DataBinder.Eval(FormView1.DataItem, "AdditionalStaffID").ToString();
 
            string[] ids = csv.Split('|');
             
            for (int i = 0; i < ids.Length - 1; i++ )
            {
                ddlAdditionalStaff.Items.FindItemByValue(ids[i].Trim()).Checked = true;
            }
 
        }
    }
}

Tags
ComboBox
Asked by
Ben
Top achievements
Rank 1
Answers by
Ben
Top achievements
Rank 1
Share this question
or