radcombobox getting populated two times with same records

1.2k Views Asked by At

I am Using radcombobox in asp.net gridview. I have used ItemTemplate tag of radcombobox for putting a checkbox in it for multiple selection of records my mark up is

<telerik:RadComboBox TabIndex="2" ID="rcbDept" runat="server" 
         EmptyMessage="--Select Department--"
         AllowCustomText="true" EnableScreenBoundaryDetection="false" 
         Width="100px" EnableTextSelection="false"
         Filter="Contains" Height="200" OnClientDropDownClosed="DropDownClosed"
         OnClientFocus="ClientFocus">
         <ItemTemplate>
             <asp:CheckBox runat="server" ID="chk1" onclick="onCheckBoxClick(this)" 
                  Text='<%# DataBinder.Eval(Container.DataItem, "dept_name") %>' />
         </ItemTemplate>
  </telerik:RadComboBox>

I have used this in EmptyDataTemplate EditTemplate & FooterTemplate of Gridview.

I am populating the Combobox in RowCreated Event

protected void gv1_RowCreated(object sender, GridViewRowEventArgs e)
{
     int a = 0;
     RadComboBox rcbDept1 = (RadComboBox)e.Row.FindControl("rcbDept");
     if (rcbDept1 != null)
     {
        if (rcbDept1.Items.Count == 0)
        {
           rcbDept1.DataSource = obj.FillRcbDepartment(a);
           rcbDept1.DataTextField = "dept_name";
           rcbDept1.DataValueField = "dept_cd";
           rcbDept1.DataBind();
        }
     }
  }

My problem is that if there are 5 record in department the it gets duplicated and combobox fills with 10 records. Where am I going wrong plz suggest.

1

There are 1 best solutions below

3
On

Try removing the function call

rcbDept1.DataBind();

I donno much about dataBind, but what i know is databind keeps your control updated whenever its datasource changes (i.e. on addition or removal of new items.).

I hope my answer helped you.