3

我有一个我认为应该是直截了当的问题。我有一个启用了 FormTemplate 编辑和 AJAX 的 RadGrid。FormTemplate 中的一个字段是一个 RadComboBox,其中填充了美国州的选择。我可以将 RadComboBox 绑定到数据源以填充所有项目,但我无法设置 SelectedValue 属性。

当为 RadGrid 上的一行单击 Edit 按钮时,将加载此 RadComboBox。使用自定义 FormTemplate 并通过 AJAX 加载正在编辑的行的内容。

4

2 回答 2

5

如果您是 DataBinding,它实际上就像添加一样简单

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

在 RadComboBox 的 FormTemplate 声明中。

但是,如果您想以编程方式确定要选择的值,则需要在 RadGrid 中实现 ItemDataBound,如下例所示

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;
        } 
    } 
于 2010-04-29T23:08:17.807 回答
1

最初清除 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
于 2011-05-17T13:23:27.067 回答