Combining database columns in RadComboBox

2 posts, 0 answers
  1. Clive Hoggar
    Clive Hoggar avatar
    348 posts
    Member since:
    Nov 2008

    Posted 10 Nov 2012 Link to this post

    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>
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 12 Nov 2012 Link to this post

    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.
Back to Top