在 telerik:RadGrid 内设置 telerik:GridDropDownColumn 的默认值

发布于 2024-08-14 06:01:40 字数 817 浏览 5 评论 0原文

我有一个绑定到 SQL 数据源的 telerik:RadGrid。其中一列用于“位置”,它实际上是另一个表中的查找值。

<telerik:GridDropDownColumn 
     DataField="d_location_id" 
     DataSourceID="dsLocation" 
     UniqueName="d_location_id" 
     DataType="System.Int32" 
     ListValueField="d_location_id" 
     ListTextField="Abbreviation" 
     HeaderText="Location">
</telerik:GridDropDownColumn>

我的位置列表存储在 ObjectDataSource 中,它绑定到静态 DataTable 并已按字母顺序排序。我想做的是能够为此下拉菜单设置默认选项。

例如,假设我有以下位置:

1   Home    
2   Work
3   Parents
4   Car

我希望将“Parents”作为我的默认值。

Telerik 上的此示例显示了类似于以下内容的内容我正在努力做。如果您单击“添加新记录”,您会注意到默认城市是柯克兰,我正在尝试弄清楚在添加新记录时如何使用伦敦作为默认城市。

I have a telerik:RadGrid that is bound to a SQL Data Source. One of the columns is for "Location" which is really a look up value in another table.

<telerik:GridDropDownColumn 
     DataField="d_location_id" 
     DataSourceID="dsLocation" 
     UniqueName="d_location_id" 
     DataType="System.Int32" 
     ListValueField="d_location_id" 
     ListTextField="Abbreviation" 
     HeaderText="Location">
</telerik:GridDropDownColumn>

My list of locations is stored in an ObjectDataSource, which is bound to a static DataTable and sorted alphabetically for me already. What I would like to do is be able to set the default option for this dropdown.

For example, suppose I have the following locations:

1   Home    
2   Work
3   Parents
4   Car

I would like to have Parents be my default value.

This sample on Telerik shows something similar to what I'm trying to do. If you click "Add New Record", you'll notice the default city is Kirkland and I'm trying to figure out how to use London as the default when adding a new record.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事灯 2024-08-21 06:01:40

不确定这是否是最好或最直接的方法,但它确实有效。

protected void gridMyInfo_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item.IsInEditMode && e.Item.ItemIndex < 0)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        GridEditManager editMan = editedItem.EditManager;

        GridDropDownListColumnEditor editor = editMan.GetColumnEditor("d_location_id") as GridDropDownListColumnEditor;
        editor.ComboBoxControl.SelectedIndex = editor.ComboBoxControl.Items.FindItemIndexByText("Parents");
    }
}

Not sure if it is the best or most straightforward way or not, but it does work.

protected void gridMyInfo_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item.IsInEditMode && e.Item.ItemIndex < 0)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        GridEditManager editMan = editedItem.EditManager;

        GridDropDownListColumnEditor editor = editMan.GetColumnEditor("d_location_id") as GridDropDownListColumnEditor;
        editor.ComboBoxControl.SelectedIndex = editor.ComboBoxControl.Items.FindItemIndexByText("Parents");
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文