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

How to rebind the radcombobox

1 Answer 140 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mohammed
Top achievements
Rank 1
Mohammed asked on 06 Jan 2014, 12:23 PM
Hi,
i'm using two radcombobox inside a radgrid editform template
<div class="art-layout-cell layout-item-1" style="width: 100%;">
    <div class="art-layout-cell layout-item-4" style="width: 30%;">
        <asp:Label ID="label_SelectCompany" AssociatedControlID="cmb_company" runat="server" Text="Company Name:" />
    </div>
    <div class="art-layout-cell layout-item-4" style="width: 60%;">
        <telerik:RadComboBox runat="server" ID="cmb_company" Height="250" AppendDataBoundItems="True" CausesValidation="False" CollapseDelay="10" SelectedValue='<%# Bind("CompanyID") %>'
            DataMember="DefaultView" AutoPostBack="true" ExpandDelay="0" ItemRequestTimeout="0" Width="80%" MarkFirstMatch="True" EmptyMessage="- Select Company -"
            DataSourceID="SqlDataSource_Company" DataTextField="CompanyName" DataValueField="ID" OnSelectedIndexChanged="cmb_company_SelectedIndexChanged" />
        <asp:RequiredFieldValidator ID="CompanyRequired" runat="server" ControlToValidate="cmb_company" ErrorMessage="*" ForeColor="Red" ValidationGroup="CompanyGroup" />
    </div>
</div>  <%-- cmb_company --%>
<div class="art-layout-cell layout-item-1" style="width: 100%;">
    <div class="art-layout-cell layout-item-4" style="width: 30%;">
        <asp:Label ID="label_CommercialActivity" AssociatedControlID="cmb_commercialActivity" runat="server" Text="Commercail Activity:" />
    </div>
    <div class="art-layout-cell layout-item-4" style="width: 60%;">
        <telerik:RadComboBox runat="server" ID="cmb_commercialActivity" AppendDataBoundItems="True" CausesValidation="False" CollapseDelay="10" DataMember="DefaultView"
            ExpandDelay="0" ItemRequestTimeout="0" Width="80%" MarkFirstMatch="True" EmptyMessage="- Select Commercial Activity -" SelectedValue='<%# Bind("EmployeeCommercialActivityID") %>'
            DataSourceID="SqlDataSource_CommercialActivity" DataTextField="CommercialActivityEnglishName" DataValueField="ID" />
        <%--<asp:RequiredFieldValidator ID="CommercialActivityRequired" runat="server" ControlToValidate="cmb_commercialActivity" ErrorMessage="*" ForeColor="Red" ValidationGroup="CompanyGroup" />--%>
    </div>
</div>  <%-- cmb_commercialActivity  --%>

and the sqldatasource is:
<asp:SqlDataSource ID="SqlDataSource_CommercialActivity" runat="server" ConnectionString="<%$ ConnectionStrings:HRSystemDataBaseConnection %>" SelectCommand="SELECT APP_CompaniesCommercialActivities.ID, APP_CommercialActivities.CommercialActivityEnglishName FROM APP_CompaniesCommercialActivities INNER JOIN APP_CommercialActivities ON APP_CompaniesCommercialActivities.CommercialActivityID = APP_CommercialActivities.ID WHERE (APP_CompaniesCommercialActivities.CompanyID = @CompanyID) ORDER BY APP_CommercialActivities.CommercialActivityEnglishName">
    <SelectParameters>
        <asp:SessionParameter Name="CompanyID" SessionField="CompanyID" />
    </SelectParameters>
</asp:SqlDataSource>
                                   
<asp:SqlDataSource ID="SqlDataSource_Company" runat="server" ConnectionString="<%$ ConnectionStrings:HRSystemDataBaseConnection %>"
    SelectCommand="SELECT ID, CompanyName FROM APP_Companies ORDER BY CompanyName" />

and the codebehind is:
Protected Sub cmb_company_SelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs)
    Session("CompanyID") = e.Value
     
    Dim _EditForm As GridEditFormItem = DirectCast(DirectCast(sender, RadComboBox).NamingContainer, GridEditFormItem)
 
    Dim _CommercialActivity As RadComboBox = DirectCast(_EditForm.FindControl("cmb_commercialActivity"), RadComboBox)
    _CommercialActivity.ClearSelection()
End Sub


when i tried to change the company name it shows an error
"Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control."



Regards,
rafsan

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 Jan 2014, 10:13 AM
Hi Mohammed,

I see that you have set the SelectedValue for the RadComboBox. You have to bind the DataValueField value to the SelectedValue as follows:

ASPX:
<EditItemTemplate>
    Company Name:
    <telerik:RadComboBox runat="server" ID="cmb_company" SelectedValue='<%# Bind("ID") %>'  AutoPostBack="true" DataTextField="CompanyName" DataValueField="ID" OnSelectedIndexChanged="cmb_company_SelectedIndexChanged". . .  />
 
    Commercail Activity:
    <telerik:RadComboBox runat="server" ID="cmb_commercialActivity" SelectedValue='<%# Bind("ID") %>' DataTextField="CommercialActivityEnglishName" DataValueField="ID". . .  />
</EditItemTemplate>

Thanks,
Princy


Tags
ComboBox
Asked by
Mohammed
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or