我有一个我认为应该直截了当的问题。我有一个支持FormTemplate编辑和AJAX的RadGrid。FormTemplate中的一个字段是一个填充了美国州选择的RadComboBox。我可以将RadComboBox绑定到数据源以填充所有项,但不能设置SelectedValue属性。
当单击RadGrid上某一行的编辑按钮时,将加载此RadComboBox。使用自定义FormTemplate,并通过AJAX加载正在编辑的行的内容。
发布于 2010-04-30 07:08:18
如果你是DataBinding,从字面上看就像添加
SelectedValue='<%# Bind("FieldName")%>'
在RadComboBox的FormTemplate声明中。
但是,如果您希望以编程方式确定要选择的值,则需要在RadGrid、like the following example中实现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;
}
}
发布于 2011-05-17 21:23:27
最初清除radcombobox的所有项,然后手动添加新项
这就是我在使用web服务时设置新项目的方式
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
https://stackoverflow.com/questions/2741163
复制相似问题