Multi Column ComboBox Show Value in edit mode

2 posts, 0 answers
  1. Perry
    Perry avatar
    62 posts
    Member since:
    Jul 2015

    Posted 15 May 2019 Link to this post

    I have built a RadGrid with a MultiColumn ComboBox nested in an EditItemTemplate column This is the ASP code for the ComboBox.  I based my design from the Telerik example from this Demo-Site

                                               <telerik:RadComboBox RenderMode="Lightweight" runat="server" ID="RadComboBox1" EnableLoadOnDemand="True"
                                                       DataTextField="FullName" OnItemsRequested="RadComboBox1_ItemsRequested" DataValueField="EID" AutoPostBack="true"
                                                       HighlightTemplatedItems="true" Height="140px" Width="220px" DropDownWidth="420px"
                                               <li class="col1">EID</li>
                                               <li class="col2">FullName</li>


    And this is the C# code behind for the Combo

    protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
                string sql = "SELECT [EID], [FullName] from LU_Employees  WHERE FullName LIKE @FullName + '%'";
                SqlDataAdapter adapter = new SqlDataAdapter(sql,
                adapter.SelectCommand.Parameters.AddWithValue("@FullName", e.Text);
                DataTable dt = new DataTable();
                RadComboBox comboBox = (RadComboBox)sender;
                // Clear the default Item that has been re-created from ViewState at this point.
                foreach (DataRow row in dt.Rows)
                    RadComboBoxItem item = new RadComboBoxItem();
                    item.Text = row["FullName"].ToString();
                    item.Value = row["EID"].ToString();
                    item.Attributes.Add("FullName", row["EID"].ToString());


    The comboBox works but I now need to solve the problem of showing the Selected Item when I am editing the record.  Right now when I click the edit button the ComboBox  is blank.  I read the Telerik information at This link and here is the code I used for the OnItemDataBoundHandler method;

    protected void OnItemDataBoundHandler(object sender, GridItemEventArgs e)
                if (e.Item.IsInEditMode)
                    GridEditableItem item = (GridEditableItem)e.Item;
                    if (!(e.Item is IGridInsertItem))
                        RadComboBox combo =
                        RadComboBoxItem preselectedItem = new RadComboBoxItem();
                        preselectedItem.Text = item["FullName"].Text;
                        preselectedItem.Value = item["EID"].Text;
                        combo.Items.Insert(0, preselectedItem);
                        combo.SelectedIndex = 0;


    When I run the app and click the edit link to to edit the record I get an error message When the code line "preselectedItem.Text = item["FullName"].Text;" runs.  I have taken a screen shot of the error and have attached for your review


    Can someone please tell me what I have done wrong with this code?

  2. Perry
    Perry avatar
    62 posts
    Member since:
    Jul 2015

    Posted 16 May 2019 in reply to Perry Link to this post

    Does Telerik monitor this forum any more?
Back to Top