首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在RadGrid的FormTemplate中设置Telerik RadComboBox的SelectedValue属性

如何在RadGrid的FormTemplate中设置Telerik RadComboBox的SelectedValue属性
EN

Stack Overflow用户
提问于 2010-04-30 06:22:27
回答 2查看 36.8K关注 0票数 3

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

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

EN

回答 2

Stack Overflow用户

发布于 2010-04-30 07:08:18

如果你是DataBinding,从字面上看就像添加

代码语言:javascript
运行
复制
SelectedValue='<%# Bind("FieldName")%>'

在RadComboBox的FormTemplate声明中。

但是,如果您希望以编程方式确定要选择的值,则需要在RadGrid、like the following example中实现ItemDataBound

代码语言:javascript
运行
复制
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
EN

Stack Overflow用户

发布于 2011-05-17 21:23:27

最初清除radcombobox的所有项,然后手动添加新项

这就是我在使用web服务时设置新项目的方式

代码语言:javascript
运行
复制
     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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2741163

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档