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

combobox's loading twice

1 Answer 163 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Byzza
Top achievements
Rank 2
Byzza asked on 28 Mar 2011, 05:17 AM

ok, so I have 4 combo boxes bound to SQL Data sources which are meant to load based on the value of a 5th combo box.  Under normal postback conditions this works fine without any issues.

I start to run into problems though when I programattically set the value of the 5th Combo Box on load.  When this happens the other 4 combos are loading their datasets twice, and with 3 of them having AppendDataitems="True" i end up with duplicates.

Any help would be greatly appreciated.
Thank you

ASP.NET Code Example rcbcsType=Combo 5, rcbType2 is one of the other 4

  <telerik:RadComboBox ID="rcbcsType" runat="server" AppendDataBoundItems="true" AutoPostBack="true"
                    DataSourceID="sdsConfig" DataTextField="csTypeName" DataValueField="csType">
                    <Items>
                        <telerik:RadComboBoxItem runat="server" Text="" Value="" />
                        <telerik:RadComboBoxItem runat="server" Text="All" Value="-1" />
                    </Items>
                </telerik:RadComboBox>
<asp:SqlDataSource ID="sdsConfig" runat="server" SelectCommand="SELECT csType, csTypeName FROM tblConfig"
        ConnectionString="<%$ ConnectionStrings:csBIR %>"></asp:SqlDataSource>
  
  
 <telerik:RadComboBox ID="rcbType2" runat="server" MarkFirstMatch="true" AppendDataBoundItems="true"
                    DataSourceID="sdsType2" DataTextField="Code" DataValueField="Code" Skin="Default">
                        <Items>
                            <telerik:RadComboBoxItem Value="" Text="" />
                        </Items>
                </telerik:RadComboBox>
  
    <asp:SqlDataSource ID="sdsType2" runat="server" ConnectionString="<%$ ConnectionStrings:csBIR %>"
        SelectCommand="SELECT '' as code, '' as codeType UNION SELECT [Code], [CodeType] FROM [rCodes] WHERE (([active] = 1) AND [CodeType] = 'ComplaintType' AND ([Type1] = @Type1)) Order By Code">
        <SelectParameters>
            <asp:ControlParameter Name="Type1" ControlID="rcbcsType" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>

VB.NET Code Example

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim cstype As String = Request.QueryString("type")
        If Not Page.IsPostBack Then
            If csType <> "" Then
                gblcsType = csType.ToUpper
            End If
        End If
  
End Sub
  
Protected Sub rcbcsType_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles rcbcsType.DataBound
        If Not Page.IsPostBack Then
            If gblcsType <> "" Then
                Me.rcbcsType.SelectedValue = gblcsType 
                Me.rcbcsType.Enabled = False
            End If
        End If
    End Sub

1 Answer, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 01 Apr 2011, 01:40 PM
Hi,

Once you preselect a value from the "rcbcsType" combobox, the OnDataBound event of the "rcbcsType" combobox is fired twice.
That's why you end up with data duplication.
Since this issue appears only when you have such a custom scenario, we should use some validation in order to workaround it.

My suggestion is to use a boolean variable which will indicate whether an item has been preselected .
If an item has been preselected, when the OnDataBound event of the "rcbcsType" combobox  is fired for the first time, to clear the items from the second "rcbType2" , which have just been added.
Thus you will have only the items added when the event is fired for the second time.

All the best,
Dimitar Terziev
the Telerik team
Tags
ComboBox
Asked by
Byzza
Top achievements
Rank 2
Answers by
Dimitar Terziev
Telerik team
Share this question
or