Could not bind combo box based on another combo selection in rad grid edit form

3 posts, 1 answers
  1. hari
    hari avatar
    2 posts
    Member since:
    Aug 2011

    Posted 18 Aug 2011 Link to this post

    I am trying to update values of first combobox based on another combobox's sected value in the rad grid's formtemplate.It si not updating properly.Could you please help me to fix this problem.
    Here is my code.

    ASPX

     

     

    <tr>

     

     

     

    <td align="left">

     

     

     

    <telerik:RadComboBox EnableScreenBoundaryDetection="false" ID="rdcbCustomer" runat="server" Skin="Vista" AppendDataBoundItems="true"

     

     

     

    Filter="StartsWith" DataSource='<%# Iif (TypeOf Container is GridEditFormInsertItem, ActiveCustomers, Customers) %>'

     

     

     

    DataTextField="Name" DataValueField="CustomerId" AutoPostBack="true" CausesValidation="false" OnSelectedIndexChanged="rdcbCustomer_OnSelectedIndexChanged">

     

     

     

    <Items>

     

     

     

    <telerik:RadComboBoxItem Text="---Select---" Value="-1" Selected="true" />

     

     

     

    </Items>

     

     

     

    </telerik:RadComboBox>

     

     

     

    <br />

     

     

     

    <asp:RequiredFieldValidator ID="customerValid" ControlToValidate="rdcbCustomer" Text="Customer is required."

     

     

     

    Display="dynamic" runat="server" InitialValue="---Select---" /><br />

     

     

     

    </td>

     

     

     

    </tr>

     

     

     

    <tr align="left">

     

     

     

    <td>

     

     

     

    <b>Party: *</b>

     

     

     

    </td>

     

     

     

    </tr>

     

     

     

    <tr>

     

     

     

    <td align="left">

     

     

     

    <telerik:RadComboBox EnableScreenBoundaryDetection="false" ID="rdcbParty" runat="server" Skin="Vista" AppendDataBoundItems="true"

     

     

     

    Filter="StartsWith" DataSource='<%# Parties %>' DataTextField="Name" DataValueField="PartyId">

     

     

     

    <Items>

     

     

     

    <telerik:RadComboBoxItem Text="---Select---" Value="-1" Selected="true" />

     

     

     

    </Items>

     

     

     

    </telerik:RadComboBox>

     

     

     

    <br />

     

     

     

    <asp:RequiredFieldValidator ID="partyValid" ControlToValidate="rdcbParty" Text="Party is required."

     

     

     

    Display="dynamic" runat="server" InitialValue="---Select---" /><br />

     

     

     

    </td>

     

     

     

    </tr>

     



    ASPX.VB

     

     

    Protected Sub rdcbCustomer_OnSelectedIndexChanged(ByVal o As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)

     

    Parties = LoadPartiesListByCustomer(e.Value)

     

     

    Dim combo1 As RadComboBox = TryCast(o, RadComboBox)

     

     

     

    Dim editItem As GridEditFormItem = TryCast(combo1.NamingContainer, GridEditFormItem)

     

     

     

    Dim combo2 As RadComboBox = TryCast(editItem.FindControl("rdcbParty"), RadComboBox)

     

    combo2.DataSource = Parties

     

     

    End Sub

     

     

     

    Protected Function LoadPartiesListByCustomer(ByVal cust_id) As IList(Of Party)

     

     

     

    Dim party As IList(Of Party) = New List(Of Party)()

     

     

     

    Dim dtParty As DataTable = cDA.GetPartiesByCustomer(cust_id)

     

     

     

    If dtParty.Rows.Count > 0 Then

     

     

     

    For Each dr As DataRow In dtParty.Rows

     

     

     

    Dim p As New Party()

     

    p.PartyId =

     

    Convert.ToInt32(dr("PartyId"))

     

    p.Name =

     

    Convert.ToString(dr("Name"))

     

    p.IsActive =

     

    Convert.ToBoolean(dr("IsActive"))

     

    party.Add(p)

     

     

    Next

     

     

     

    End If

     

     

     

    'Parties.Clear()

     

     

    Parties = party

     

     

    Return Parties

     

     

     

    End Function

     

    Please help me to fix this problem
  2. Answer
    Rory
    Rory avatar
    159 posts
    Member since:
    Jul 2007

    Posted 18 Aug 2011 Link to this post

    Try Calling a Combo2.DataBind() right after you set the datasource.
  3. hari
    hari avatar
    2 posts
    Member since:
    Aug 2011

    Posted 19 Aug 2011 Link to this post

    Thanks for the replay Rory!!
    I tried to use databind  with below lines and it worked.Thank you very much for chaning my thoghts into different directions.It really helped.

    combo2.DataTextField =

     

    "Name"

     

    combo2.DataValueField =

     

    "PartyId"

     

Back to Top