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

Displaying unmatched DataField text in grid with ComboBox

2 Answers 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Milan Gurung
Top achievements
Rank 1
Milan Gurung asked on 10 Sep 2008, 04:35 PM
Hi,

Is it possible to display the unmatched value in the grid rather than empty text? For instance..

<

telerik:GridDropDownColumn HeaderText="Client" UniqueName="Budget_Client" DataSourceID="SrcForClient" DataField="Budget_Client" ListTextField="ClientName" ListValueField="ClientName"></telerik:GridDropDownColumn>


On the above code, I am binding a dropdown list to a object datasource. The problem is if DataField does not match item in the field, it display blank in the grid column. Ideally I would to have user see the original value (Data Field) before going to edit mode for selecting item in the dropdown list...

Any suggestion would be appreciated.

Thanks.
Milan G

2 Answers, 1 is accepted

Sort by
0
Accepted
Veli
Telerik team
answered on 14 Sep 2008, 06:22 PM
Hi Milan Gurung,

GridDropDownColumn's intended usage, was to be bound to a data source where each item from RadGrid would have its representation as a value in the dropdown column's source. Indeed, if an item in RadGrid cannot find a matching value in the lookup source, then it defaults to an empty string. To work around this behavior, you need to manually modify your item cells to make sure they will show the original data source value. This can be done in the PReRender event of the grid in the following way:

void RadGrid1_PreRender(object sender, EventArgs e) 
    foreach (GridDataItem item in RadGrid1.Items) 
    { 
        if (item["ColumnUniqueName"].Text == ""
            item["ColumnUniqueName"].Text = (item.DataItem as DataRowView)["ColumnUniqueName"].ToString(); 
    } 

The above code loops through all the items in the current page of the grid and sets the cell values inside an arbitrary column to the default value from the data source.

Greetings,
Veli
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Milan Gurung
Top achievements
Rank 1
answered on 15 Sep 2008, 11:36 AM
Many thanks Veli!

Cheers,
Milan G
Tags
Grid
Asked by
Milan Gurung
Top achievements
Rank 1
Answers by
Veli
Telerik team
Milan Gurung
Top achievements
Rank 1
Share this question
or