Checkbox loses its checked state, and click event with RadDataPager

2 posts, 0 answers
  1. Akinola
    Akinola avatar
    4 posts
    Member since:
    Mar 2012

    Posted 15 Jun 2012 Link to this post


    I have a page that uses the RadListView control and a RadDataPager control. The RadListView control holds checkboxes with each item. The checkboxes have been wired to a click event using jQuery (see below). 

    $(document).ready(function () {
               //Update the hidden variable with all fieldchoices to be added
                $('#FieldSet1').find("input[type='checkbox']").click(function () {
    //do something


    However, when I page to another page using the RadDataPager, the checkboxes lose their onclick event AND the checked state. 

    Does anyone have any idea how to keep the checkbox wired to the click event, and also how to keep the checkboxes checked?

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Jun 2012 Link to this post

    Hi Akinola,

    Here is the sample code snippet that I tried to achieve your scenario.

    <telerik:RadListView ID="RadListView1" Width="97%" AllowPaging="True" runat="server" AllowSorting="true" ItemPlaceholderID="ProductsHolder" DataKeyNames="ProductID" OnNeedDataSource="RadListView1_NeedDataSource"  onitemdatabound="RadListView1_ItemDataBound" >
        <fieldset style="width: 760px;" id="RadListView1">
           <asp:Panel ID="ProductsHolder" runat="server" />
         <asp:CheckBox ID="CheckBox1" runat="server"  OnClick="onClick(this)" oncheckedchanged="CheckBox1_CheckedChanged" />

    <script type="text/javascript">
      function onClick(e)

    private Hashtable CustomersChecked
          object res = ViewState["_cc"];
          if (res == null)
               res = new Hashtable();
               ViewState["_cc"] = res;
          return (Hashtable)res;
    protected void RadListView1_ItemDataBound(object sender, RadListViewItemEventArgs e)
        if (e.Item is RadListViewDataItem)
            RadListViewDataItem item = e.Item as RadListViewDataItem;
            string ProductID = item.GetDataKeyValue("ProductID").ToString();
            CheckBox box = (CheckBox)item.FindControl("CheckBox1");
            object isChecked = null;
            isChecked = CustomersChecked[ProductID];
            if (isChecked != null)
               box.Checked = (bool)isChecked == true;
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        CheckBox chk = (CheckBox)sender;
        Hashtable target = CustomersChecked;
        if (chk.Checked == true)
           RadListViewDataItem dataItem = (RadListViewDataItem)chk.NamingContainer;
           string customerID = dataItem.GetDataKeyValue("ProductID").ToString();
           target[customerID] = true;
           RadListViewDataItem dataItem = (RadListViewDataItem)chk.NamingContainer;
           string customerID = dataItem.GetDataKeyValue("ProductID").ToString();
           target[customerID] = null;

    Hope this helps.

Back to Top