How to RadComboBox databind?

3 posts, 0 answers
  1. Yoongu
    Yoongu avatar
    16 posts
    Member since:
    Sep 2014

    Posted 31 Oct 2014 Link to this post

    Hi,

    I wonder how to bind a ComboBox in the new Control DataForm.

    I have created a script as follows.

    aspx
    ....
            <telerik:RadAjaxPanel ID="RadAjaxPanel2" runat="server" Height="100%" Width="100%" HorizontalAlign="NotSet" LoadingPanelID="baseLoadingPanel" OnAjaxRequest="RadAjaxPanel2_AjaxRequest">
                <telerik:RadDataForm ID="detailsView" runat="server" OnPreRender="detailsView_PreRender">
                    <ItemTemplate>
                        <table class="InputTable" border ="1">
                            <tr>
                                <td>
                                       <telerik:RadComboBox ID="comboBoxItem" runat="server"  SelectedValue='<%# Eval("item") %>' Width="100%" ValueType="System.String">
                                       </telerik:RadComboBox>
                                </td>
                            </tr>
    ...


    aspx.cs
    protected void detailsView_PreRender(object sender, EventArgs e)
    {
        RadComboBox comboBox = (RadComboBox)detailsView.FindControl("comboBoxItem");
        if(comboBox!=null)
        {
            DataTable dataTable = new DataTable();
            dataTable = SelectCommonCode(codeKind, whereclause);
     
            comboBox.DataSource = dataTable;
            comboBox.DataTextField = "codename";
            comboBox.DataValueField = "code";
            comboBox.DataBind();
        }
             
    }

    however, if(comboBox!=null)  <---- here is always null.

    Please tell me the right way.

    thx
  2. Yoongu
    Yoongu avatar
    16 posts
    Member since:
    Sep 2014

    Posted 02 Nov 2014 in reply to Yoongu Link to this post

    I have solved this problem by using a ItemsRequested event.

    protected void comboBoxHard_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        RadComboBox comboBox = (RadComboBox)sender("comboBoxItem");
        if(comboBox!=null)
        {
            DataTable dataTable = new DataTable();
            dataTable = SelectCommonCode(codeKind, whereclause);
      
            comboBox.DataSource = dataTable;
            comboBox.DataTextField = "codename";
            comboBox.DataValueField = "code";
            comboBox.DataBind();
        }
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Yoongu
    Yoongu avatar
    16 posts
    Member since:
    Sep 2014

    Posted 02 Nov 2014 in reply to Yoongu Link to this post

    Oh my mistake.

    (RadComboBox)sender("comboBoxItem"); ----> (RadComboBox)sender;

    It is inconvenient to not be able to edit the post in the forum. 
Back to Top