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

Setting multiple ListTextField values to a GridDropDownColumn in RadGrid View mode (NOT in RadGrid Edit mode)

3 Answers 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 1
George asked on 05 Dec 2012, 10:41 AM

Hello,

i have a GridDropDownColumn connected to a DataSource and i get an error when i try to set the ListTextField property like this: ListTextField = "Field1, Field2". How can i achieve this programmatically in radgrid view mode?

I have written the following code to achieve this in radgrid edit mode:

if (e.Item is GridEditableItem && e.Item.IsInEditMode)
       {
 
           GridEditableItem editItem = (GridEditableItem)e.Item;
 
           RadComboBox combo = (RadComboBox)editItem["Field1"].Controls[0];
 
           combo.ItemDataBound += new RadComboBoxItemEventHandler(combo_ItemDataBound);
 
       }
 
   void combo_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
   {
       RadComboBoxItem item = (RadComboBoxItem)e.Item;
 
       DataRowView dr = (DataRowView)e.Item.DataItem;
 
       item.Text = item.Text + " ( " + dr["Field2"].ToString() + " " + dr["Field3"].ToString() + " ) ";
 
   }

Thank you very much.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 05 Dec 2012, 11:06 AM
Hi,

Here is the sample code that I tried to achieve your scenario.
C#:
protected void RadGrid2_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 if (e.Item is GridDataItem)
 {
   GridDataItem item = (GridDataItem)e.Item;
   DataRowView row = (DataRowView)e.Item.DataItem;
   item["uniquename"].Text = row["Field1"].ToString() + " " + row["Field2"].ToString();
 }
}

Thanks,
Princy.
0
George
Top achievements
Rank 1
answered on 05 Dec 2012, 11:39 AM
Princy, thank you very much for your quick answer.

Something with the code you wrote is wrong: I take the message: "Field1 is neither a DataColumn nor a DataRelation for table DefaultView".

I think that the problem is that this code binds data from the datasource connected to the RadGrid and not to the GridDropDownColumn.
0
Princy
Top achievements
Rank 2
answered on 06 Dec 2012, 04:48 AM
Hi,

I was able to replicate this issue when I binded the dropdown with a field that does not exist in the datatable. Please make sure that the field you are binding exists in the datasource of the GridDropDownColumn. Hope this helps.

Thanks,
Princy.
Tags
Grid
Asked by
George
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
George
Top achievements
Rank 1
Share this question
or