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

[Solved] GridDropDownColumn EmptyListItemText

2 Answers 107 Views
Grid
This is a migrated thread and some comments may be shown as answers.
IT Support
Top achievements
Rank 1
IT Support asked on 13 Jan 2010, 11:18 AM
Hi,

Is it possible to change the value of the GridDropDownColumn EmptyListItemText at runtime in the ItemDataBound event?
I want to change the value for that EmptyListItem depending on the data which this item is bound to...

Kind Regards,
Raymond

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 Jan 2010, 02:05 PM
Hello Raymond,

Try out the following code to alter the EmptyListText for a GridDropDownColumn:
c#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            GridDropDownColumn column = (GridDropDownColumn)RadGrid1.MasterTableView.GetColumn("DropDownColumnUniqueName");             
            if (dataItem["BoundColumnUniqueName"].Text == "MyText"
            {                 
                column.EmptyListItemText = "Custom Text"
                column.EmptyListItemValue = "1"
            } 
            else 
            { 
                column.EmptyListItemText = "Select Text"
                column.EmptyListItemValue = "0"
            } 
        } 
    } 

Thanks
Princy.
0
IT Support
Top achievements
Rank 1
answered on 13 Jan 2010, 02:53 PM
Hi.

Thanks for the reply. Unfortunately, that does not seem to work, the text remains the "EmptyListItemText" value defined in the aspx file...

I was able to do it as follows:
if (e.Item is GridDataItem && e.Item.DataItem is DataRowView) 
    TableCell cell = (e.Item as GridDataItem)["MyColumn"]; 
    if (cell.Text == m_UnknownDropDownEntryText) 
    { 
        cell.Text = string.Format("{0} ({1})", m_UnknownDropDownEntryText, (e.Item.DataItem as DataRowView)["MyColumn"]); 
    } 

This seems to work, except after a postback, the column remains empty, I suspect because the OnItemDataBound event is not fired during the second postback...

Any ideas on how to fix this?

Kind Regards,
Raymond

Tags
Grid
Asked by
IT Support
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
IT Support
Top achievements
Rank 1
Share this question
or