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

How to RadComboBox databind?

2 Answers 1219 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Yoongu
Top achievements
Rank 1
Yoongu asked on 31 Oct 2014, 08:04 AM
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 Answers, 1 is accepted

Sort by
0
Yoongu
Top achievements
Rank 1
answered on 03 Nov 2014, 12:40 AM
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();
    }
0
Yoongu
Top achievements
Rank 1
answered on 03 Nov 2014, 12:47 AM
Oh my mistake.

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

It is inconvenient to not be able to edit the post in the forum. 
Tags
DataForm
Asked by
Yoongu
Top achievements
Rank 1
Answers by
Yoongu
Top achievements
Rank 1
Share this question
or