checkboxes filled from linq datasource

2 posts, 1 answers
  1. Adam
    Adam avatar
    17 posts
    Member since:
    Sep 2012

    Posted 05 Sep 2012 Link to this post

    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
  2. Answer
    Ivana avatar
    657 posts

    Posted 10 Sep 2012 Link to this post

    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">
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
        SelectCommand="SELECT [ClientID], [ClientName], [ReceivedEmail] FROM [BooleanTable]">
    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,
    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.
Back to Top