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

RadComboBoxItemCollection as parameter

3 Answers 97 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Eric Schoenholzer
Top achievements
Rank 2
Eric Schoenholzer asked on 20 Jun 2008, 11:00 PM

I try to use Items from RadComboBox as input for a ControlParameter in a ObjectDataSource (or SqlDataSource). But I get an error: 

Type 'Telerik.Web.UI.RadComboBoxItemCollection' in Assembly 'Telerik.Web.UI, Version=2008.1.619.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4' is not marked as serializable. 

Why I do that? I have expanded the ComboBox in a ItemTemplate with checkboxes and I need to find out which boxes are checked. Normally I loop over the collection and check the checkboxes. 

But where to do that when the ComboBox is bound to a ObjectDataSource or SqlDataSource? 

Overriding the control and add a new property? Is there any event to use?

Telerik: Is it possible to make Items serializable?

Thanks for any suggestions

Eric

3 Answers, 1 is accepted

Sort by
0
Rosi
Telerik team
answered on 23 Jun 2008, 03:58 PM
Hello Eric,

You cannot mark the items as serializable, but you can hook on the DataBound event of RadComboBox and check in its event  handler if the checkboxes inside the items are checked or not.

Also, could you please provide us with more details about the task that you try to achieve? If we have more details we can provide you more specific instructions.


Regards,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Eric Schoenholzer
Top achievements
Rank 2
answered on 23 Jun 2008, 07:29 PM
Thanks, but doesn't help me.

My scenario is:
- RadComboBox with Checkboxes as ItemTemplate
- RadComboBox  is set to AutoPostBack
- RadComboBox as input for a DataSource control (SelectedValue is no problem, problem is all the checked items)

I need to use the selected items / checkboxes as input for a SqlDataSource or ObjectDataSource. As input parameter for a datasource, you can use a property of a control.

But the items collection doesn't work (not serializable) and SelectedValue isn't valid. And in DataBound event I see no way to set the input parameter for the datasource.

Eric
0
Rosi
Telerik team
answered on 25 Jun 2008, 06:48 AM
Hi EricSch,

I suggest you  bind the control  through code-behind instead of using declarative datasource.Then you can iterate combobox's items and check which items are checked. After that you ca use parametric queries to bind the datasource.

For example
  protected void Page_Load(object sender, EventArgs e)  
    {  
        int checkedItems = 0;  
        for(int i=0; i<radcombobox.Items.Count)  
        {  
            CheckBox checkbox = (CheckBox) radcombobox.Items[i].FindControl("CheckBox1"));  
            if(checkbox.CheckedChanged)  
                checkedItems++;  
        }  
 
         
          string connstr = ConfigurationManager.ConnectionStrings["YourConnectionString"].ConnectionString;  
       
        SqlConnection dbCon = new SqlConnection(connstr);  
        string strSelect = @"  Select * FROM SOMETABLE WHERE SOMECOLUMN  = @CheckedItems ";  
 
        SqlCommand comm = new SqlCommand(strSelect, dbCon);  
        comm.CommandType = CommandType.Text;  
 
        SqlParameter id = new SqlParameter("@CheckedItems", checkedItems);  
        comm.Parameters.Add(id);  
        dbCon.Open();  
        DataSet ds = new DataSet();
        try 
        {  
          adapter.Fill(ds);
        }  
        finally 
        {  
            dbCon.Close();  
        }  
    } 

Regards,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
ComboBox
Asked by
Eric Schoenholzer
Top achievements
Rank 2
Answers by
Rosi
Telerik team
Eric Schoenholzer
Top achievements
Rank 2
Share this question
or