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

Radlistboxitem and label for

2 Answers 131 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
blessed
Top achievements
Rank 1
blessed asked on 17 Jun 2017, 03:18 AM

Is it doable?

i have a radlistboxitem list on which i would like to add label for, so that we will be able to select the checkbox using the label not the checkbox.

 

So far, i have this code, but it is not working. Your help will be greatly appreciated.

aspx

<telerik:RadListBox runat="server" ID="testRadlist" AutoPostBack="true" RenderMode="Lightweight" CheckBoxes="true" SelectionMode="Multiple" Width="215PX">
<ItemTemplate>
    <asp:Label runat="server" Text="Text" ID="lblRadlist" AssociatedControlID=""></asp:Label>
</ItemTemplate>
<Items>
     
</Items>

 

aspx.cs

testRadlist.Items.Clear();
         
 
        testRadlist.Items.Add(new RadListBoxItem {
            Value = "Summary",
           // Text = "Summary"
        });
        testRadlist.Items.Add(new RadListBoxItem
        {
            Value = "Edit",
            //Text = "Edit"
        });
 
        for (int i=0; i < testRadlist.Items.Count; i++)
        {
            testRadlist.Items[i].DataBind();
            Label lbl = (Label)testRadlist.Items[i].FindControl("lblRadlist");
            string val = lbl.Text;
 
        }
    }
 
 

2 Answers, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 21 Jun 2017, 02:26 PM
Hello,

One option would be subscribing to the client-side click event of the Label and in the handler checking the belonging item.

 

<script type="text/javascript">           
    function checkItem(value) {
        var listbox = $find('<%= testRadlist.ClientID%>');
        var item = listbox.findItemByValue(value);
        item.set_checked(!item.get_checked());
    }
</script>
<telerik:RadListBox runat="server" ID="testRadlist"
    AutoPostBack="true"
    RenderMode="Lightweight"
    CheckBoxes="true"
    SelectionMode="Multiple"
    Width="215PX">
    <ItemTemplate>
        <asp:Label runat="server" Text="Text" ID="lblRadlist"></asp:Label>
    </ItemTemplate>
    <Items>
    </Items>
</telerik:RadListBox>
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        testRadlist.Items.Clear();
        testRadlist.Items.Add(new RadListBoxItem
        {
            Value = "Summary",
            // Text = "Summary"
        });
        testRadlist.Items.Add(new RadListBoxItem
        {
            Value = "Edit",
            //Text = "Edit"
        });
 
        for (int i = 0; i < testRadlist.Items.Count; i++)
        {
            testRadlist.Items[i].DataBind();
            Label lbl = (Label)testRadlist.Items[i].FindControl("lblRadlist");
            lbl.Attributes.Add("onclick", "checkItem('"+ testRadlist.Items[i].Value + "');");
            string val = lbl.Text;
        }
    }
}

 

Regards,
Peter Milchev
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
blessed
Top achievements
Rank 1
answered on 22 Jun 2017, 01:55 AM
thanks.
 
 
Tags
General Discussions
Asked by
blessed
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
blessed
Top achievements
Rank 1
Share this question
or