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

Binding RadComboBox in RadGrid - SQL Server

1 Answer 154 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Howard Rothman
Top achievements
Rank 1
Howard Rothman asked on 21 Jun 2010, 05:34 PM
I need to save the value of my RadComboBox to a SQL Server Database.  When the form is updated, the value of the RadCombo is always blank, even after I select a value.  Also,  I have no option in the .aspx for assigning a SelectedValue.  Here is a code snippet:

<

 

 

telerik:GridTemplateColumn HeaderText="Job No" DataField="JOB_NO">

 

 

 

<ItemTemplate

 

<%# DataBinder.Eval(Container.DataItem, "JOB_NO")%>

 

 

 

 

</ItemTemplate>

 

 

<EditItemTemplate>

 

 

<telerik:RadComboBox ID="cboJob" runat="server" Sort="Ascending" AppendDataBoundItems="true" EnableLoadOnDemand="true" Width="350px" Height="140px" DataValueField="JOB_NO" EmptyMessage="Select a Job" AutoPostBack="true" DataTextField="JOB_NO" MarkFirstMatch="true" AllowCustomText="false" DropDownWidth="300px"

 

 

 

OnItemDataBound="cboJob_ItemDataBound" HighlightTemplatedItems="true" >

 

 

 

 

 

<HeaderTemplate>
<table style="width:300px; text-align:left">

 

 

 

 

<tr>

 

<td style="width:100px;">Job No</td>

 

 

 

<td style="width:200px;">Part No</td>

 

 

</tr>

 

</table>

 

 

</HeaderTemplate>

 

 

 

 

 

 

<ItemTemplate>

 

 

 

<table style="width:300px; text-align:left">
<tr>

 

 

<td style="width:100px;"><%# DataBinder.Eval(Container.DataItem,"JOB_NO")%></td> <td style="width:300px;"><%# DataBinder.Eval(Container.DataItem,"JOBR_PART_NO")%></td>

 

 

</tr>

 

 

</table>

 

 

 

</ItemTemplate>

 

 

</telerik:RadComboBox>

 

</EditItemTemplate>

 

 

 

 

</telerik:GridTemplateColumn>

//******In the C# code behind I have the following code in the ItemDataBound for the RadGrid:
 

if

 

 

(e.Item is GridEditFormItem && e.Item.IsInEditMode)

 

 

 

{

 

 

 

GridEditFormItem editFormItem = (GridEditFormItem)e.Item;

 

TextBox txt = (TextBox)editFormItem.FindControl("CUST_ID");

 

 

 

 

GridEditableItem edititem = e.Item as GridEditableItem;

 

RadComboBox combobox = (RadComboBox)edititem.FindControl("cboJob");

 

 

 

 

DataTable dt = cData.getDataTable("SELECT DISTINCT JOB_NO, JOBR_PART_NO FROM JOB_REVISION WHERE CUST_ID = '" + txt.Text.ToString() + "' ORDER BY JOB_NO", "JOB_REVISION");

 

combobox.DataSource= dt;

combobox.DataTextField = 

 

"JOB_NO";

 

 

combobox.DataValueField = 

 

"JOB_NO";

 

 

combobox.DataBind();

 

combobox.SelectedValue =

 

DataBinder.Eval(e.Item.DataItem, "JOB_NO").ToString();

 

 

 

//*******I also have the following code for the combo:
 

 

 

 

 

protected void cboJob_ItemDataBound(object sender, RadComboBoxItemEventArgs e)

{

e.Item.Text = ((D

 

ataRowView)e.Item.DataItem)["JOB_NO"].ToString();

 

 

 

e.Item.Value = ((

 

DataRowView)e.Item.DataItem)["JOB_NO"].ToString();

 

 

 

e.Item.DataBind();

}

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Kalina
Telerik team
answered on 25 Jun 2010, 02:52 PM
Hello Howard Rothman,

I tried to replicate the issue using the code snippets provided - but unfortunately without success.

However I will suggest you preselect a RadComboBoxItem like this:

(e.Item is GridEditFormItem && e.Item.IsInEditMode)
{
    GridEditFormItem editFormItem = (GridEditFormItem)e.Item;
    TextBox txt = (TextBox)editFormItem.FindControl("CUST_ID");
    GridEditableItem edititem = e.Item as GridEditableItem;
 
    RadComboBox combobox = (RadComboBox)edititem.FindControl("cboJob");
    RadComboBoxItem preselectedItem = new RadComboBoxItem();
    preselectedItem.Text = edititem["JOB_NO"].Text;
    preselectedItem.Value = edititem["JOB_NO"].Text;
    combo.Items.Insert(0, preselectedItem);
    combo.SelectedIndex = 0;
}

If the issue persists - could you please send us a sample page that illustrates it within the support Ticket 322089  that you have additionally opened?
I am not sure that I understand the scenario that you are trying to implement - a sample will help me to provide more precise answer to you.

Thank you in advance.

Kind regards,
Kalina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
ComboBox
Asked by
Howard Rothman
Top achievements
Rank 1
Answers by
Kalina
Telerik team
Share this question
or