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

Combining database columns in RadComboBox

1 Answer 161 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Clive Hoggar
Top achievements
Rank 1
Clive Hoggar asked on 10 Nov 2012, 09:43 PM
Hi Guys

I have a combo box in the edit item of a grid column, and I wanted to combine two column values to provide the DataTextField content.
It does sort of work, in that the values in the drop down box are as expected, but after one of them is selected, the combox is empty instead of showing the selected value.  You can see I tried to use a modified query in the SQL datasource as the simplest way, but obviously it is not the complete answer. Can you put me on the right track?

Code is as below.

Thanks

Clive

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="XXXXXX"
SelectCommand="SELECT [AuthCode], ([FirstName] + [LastName]) AS [Name]  FROM [Authors]
ORDER BY [LastName], [FirstName]">
</
asp:SqlDataSource>
 
 
 
<telerik:GridTemplateColumn DataField="AuthCode" HeaderText="AuthCode" SortExpression="AuthCode"
UniqueName="AuthCode" Visible="False">
<EditItemTemplate>
    <telerik:RadComboBox ID="RadComboBox1" runat="server"
          DataSourceID="SqlDataSource2" DataTextField="Name"
          DataValueField="AuthCode" SelectedValue='<%# Bind("AuthCode") %>'
          Width="200px" AllowCustomText="True" EmptyMessage="Pick author">
    </telerik:RadComboBox>               
   </EditItemTemplate>
<ItemTemplate>             
     <asp:Label ID="AuthCodeLabel" runat="server" Text='<%# Eval("AuthCode") %>'></asp:Label>
     </ItemTemplate>
</telerik:GridTemplateColumn>

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Nov 2012, 07:38 AM
Hi,

One suggestion is that you can bind the selected value as shown below.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
    {
        GridEditFormItem editItem = (GridEditFormItem)e.Item;
        RadComboBox combo = (RadComboBox)editItem.FindControl("RadComboBox1");
        combo.SelectedValue = (string)DataBinder.Eval(e.Item.DataItem, "AuthCode").ToString();
    }
}

Thanks,
Shinu.
Tags
ComboBox
Asked by
Clive Hoggar
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or