2009-12-14 56 views
7

我有一個telerik:RadGrid綁定到SQL數據源。其中一列是「位置」,它是另一張表中真正的查找值。在telerik設置telerik:GridDropDownColumn的默認值: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,這勢必會一個靜態數據表和按字母順序排序我了。我想要做的是能夠爲此下拉列表設置默認選項。

例如,假設我有以下地點:

1 Home  
2 Work 
3 Parents 
4 Car 

我想有父母是我的默認值。

Telerik上的此示例顯示了與我正在嘗試執行的操作類似的操作。如果你點擊「添加新記錄」,你會注意到默認的城市是柯克蘭,我想知道如何在添加新記錄時使用倫敦作爲默認值。

回答

5

不確定它是否是最好的或最直接的方式,但它確實有效。

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