How to set SelectedValue attribute for Telerik RadComboBox inside RadGrid FormTemplate

I, as I think, should have a simple question. I have a RadGrid with editing FormTemplate and enabled AJAX. One of the fields in FormTemplate is RadComboBox, filled with US state elections. I can bind RadComboBox to the data source to fill all the elements, but I cannot set the SelectedValue attribute.

This RadComboBox loads when you click the "Edit" button for a row in RadGrid. A custom FormTemplate is used, and the contents of the edited string are loaded via AJAX.

+3
source share
2 answers

DataBinding, ,

SelectedValue='<%# Bind("FieldName")%>'

FormTemplate RadComboBox.

, , ItemDataBound RadGrid, :

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
       if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
        { 
            GridEditFormItem editFormItem = (GridEditFormItem)e.Item; 
            RadComboBox combo = (RadComboBox)editFormItem.FindControl("yourControlName"); 
            combo.SelectedValue= Somevalue;
        } 
    } 
+5

radcombobox,

, , , -

     ddl.ClearSelection()
            ddl.Items.Clear()

'below i'm getting the actual value and the text to display
            Using reader As IDataReader = GetClientByClientID(CInt(value))
                If reader.Read Then

'adding the item will show in the dropdown
                    Dim item As New RadComboBoxItem(reader("DisplayName").ToString, reader("ID").ToString)
                    item.Selected = True
                    ddl.Items.Add(item)

'this line will make the combobox text to be displayed correctly
                    ddl.Text = reader("DisplayName").ToString

                    ddl.DataBind()
                Else
                    ddl.Text = ""

                    ddl.ErrorMessage = "Selected Client Not Found !"
                End If

                reader.Close()
            End Using
+1

Source: https://habr.com/ru/post/1743424/


All Articles