This is a migrated thread and some comments may be shown as answers.

[Solved] Set GridDropDownColumn's DataSource when not in Editing mode

3 Answers 190 Views
Grid
This is a migrated thread and some comments may be shown as answers.
d-cpt
Top achievements
Rank 2
d-cpt asked on 11 Sep 2008, 07:17 PM
I have a GridDropDownColumn as
<telerik:GridDropDownColumn DataField="CategoryID" DataSourceID="SqlDataSource2" HeaderText="Category" ListTextField="CategoryName" ListValueField="CategoryID" UniqueName="Category"></telerik:GridDropDownColumn>
and the radgrid has DataSourceID="SqlDatSource1". EditMode=InPlace.
It works fine in Edit mode but when it is not in Edit mode, the Category column will show the first value of the DropDown if SqlDatSource1 SelectCommand returns a row with Category is null. How to keep the cell value blank in View mode in this case?
Thanks,
d-cpt

3 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 12 Sep 2008, 06:30 AM
Hello Duc,

The following approach may be appropriate for your case:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    GridEditFormItem item = e.Item as GridEditFormItem; 
    if (item != null && item.IsInEditMode) 
    { 
        item["MyColumnName"].Visible = true
    } 

<telerik:GridDropDownColumn Visible="false" DataField="ProductName" DataSourceID="SqlDataSource1" UniqueName="MyColumnName">  
</telerik:GridDropDownColumn> 

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
James
Top achievements
Rank 1
answered on 20 Sep 2009, 04:51 PM
Shouldn't there be a property on the GridDropDownColumn to show empty string if there is no match in the data source?  I don't understand the logic for wanting to show the first row. 
0
Nikolay Rusev
Telerik team
answered on 23 Sep 2009, 01:16 PM
Hello James,

Actually selecting first item when no value to select is behavior of the RadComboBox/DropDownList controls. However GridDropDownColumn has two properties that enables you to specify what value and text to be shown for this empty item: EmptyListItemText,EmptyListItemValue

All the best,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
d-cpt
Top achievements
Rank 2
Answers by
Daniel
Telerik team
James
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Share this question
or