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

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

2 Answers 92 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
hari
Top achievements
Rank 1
hari asked on 18 Aug 2011, 06:42 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Rory
Top achievements
Rank 1
answered on 19 Aug 2011, 01:49 AM
Try Calling a Combo2.DataBind() right after you set the datasource.
0
hari
Top achievements
Rank 1
answered on 19 Aug 2011, 03:25 PM
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"

 

Tags
ComboBox
Asked by
hari
Top achievements
Rank 1
Answers by
Rory
Top achievements
Rank 1
hari
Top achievements
Rank 1
Share this question
or