开发者

Set default value of telerik:GridDropDownColumn inside of telerik:RadGrid

开发者 https://www.devze.com 2022-12-14 04:11 出处:网络
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.

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.


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");
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消