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

checkboxes filled from linq datasource

1 Answer 27 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 05 Sep 2012, 07:29 AM
Hi All,

I've not had much experience with the rad controls, but what I see so far is pretty good.

I did some searching online, but either was using the wrong search terms or what I want to do is not possible.

I have a listbox on a page.  What I want to do is bind it to a linq datasource with checkboxes filled in from the datasource.

I'm hoping that I can pass in a datasource with 3 columns:

ReceivedEmail: Boolean
ClientID: Int
ClientName: String

True-1-Fred Smith
True-2-Betty White
False-3-Amy Whinehouse

This would produce a list with the three names and the first 2 items checked without any extra work in code...

I was talking to one of the other guys I work with and he said that he usually binds to a datasource and then loops through all the list items after binding has finished and then sets the checked flag..
This seemed a little inefficient, and figured that if the control handled it, why not do it in one go..

Does this make sense..??  Can it be done already..???

Many thanks

1 Answer, 1 is accepted

Sort by
0
Accepted
Ivana
Telerik team
answered on 10 Sep 2012, 06:09 AM
Hello Adam,

The following example shows how you could use the RadListBox in a scenario like yours:
<telerik:RadListBox ID="RadListBox1" runat="server" CheckBoxes="True" Width="200px"
    Height="300px" OnItemDataBound="RadListBox1_ItemDataBound"
    DataSourceID="SqlDataSource1" DataValueField="ClientID" DataTextField="ClientName">
</telerik:RadListBox>
 
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
    SelectCommand="SELECT [ClientID], [ClientName], [ReceivedEmail] FROM [BooleanTable]">
</asp:SqlDataSource>
protected void RadListBox1_ItemDataBound(object sender, RadListBoxItemEventArgs e)
{
    DataRowView dataRow = e.Item.DataItem as DataRowView;
    if(Int32.Parse(dataRow["ReceivedEmail"].ToString()) == 1){
        e.Item.Checked = true;
    }
}

More on the RadListBox specifics you can find out in its online documentation or on its online examples.

I hope this will be helpful!

Kind regards,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ListBox
Asked by
Adam
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Share this question
or