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

How to grab ListTextField of GridDropDownColumn

2 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 17 Aug 2010, 07:20 PM
Hi,

Can anyone help.  I have a grid with a GridDropDownColumn as such:

<telerik:GridDropDownColumn UniqueName="CategoryName" HeaderText="Category" DataSourceID="DDL_DS" SortExpression="DC_Name" ListTextField="DC_Name" ListValueField="DC_Id" DataField="DC_Id" />

Grouping is enabled, and when a user drags the Category Header to the grouping pane, my grid groups fine.  However, the group header displays the Id, not the Name.  I've tried using ItemDataBound as below, but I just can't seem to grab that ListTextField.

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)

{

 

 

if (e.Item is GridGroupHeaderItem)

{

 

GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;  

DataRowView groupDataRow = (DataRowView)e.Item.DataItem;

item.DataCell.Text =

 

"( " + groupDataRow["DC_Id"].ToString() + " ) " ;

 

 

}

}

Thanks in advance,
J

 

 

 

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Aug 2010, 01:52 PM
Hello Jason,

Try the following code snippet in PreRender to display name in group header.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
       foreach (GridGroupHeaderItem groupHeader in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
        {
            GridItem[] children = groupHeader.GetChildItems();
            GridDataItem child = (GridDataItem)children[0];
            DataRowView groupDataRow = (DataRowView)child.DataItem;
            groupHeader.DataCell.Text = "( " + groupDataRow["DC_Name"].ToString() + " ) ";
        }
    }

Thanks,
Princy.
0
Jason
Top achievements
Rank 1
answered on 18 Aug 2010, 04:55 PM
Princy,

Thank you for your response.  Unfortunately the snipet you provided had no effect at all.   By applying the code I supplied above in the itemdatabound, I can customize the header as such:

example DDL - id =1, name = Computers
                        id=2, name = Printers


The code line

item.DataCell.Text = "( " + groupDataRow["DC_Id"].ToString() + " ) " ;
allows me to format the id as "( id )". I can put any text in there I want.  But, I really need the Name field.  If I use DC_Name, get "DC_Name is neither a DataColumn nor a DataRelation for table GroupedTable0.

Thanks,J

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