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

Get value of GridDropDownColumn in codebehind?

6 Answers 427 Views
Grid
This is a migrated thread and some comments may be shown as answers.
al
Top achievements
Rank 1
al asked on 15 May 2008, 09:44 AM
how can i get the value of GridDropDownColumn in codebehind?


GridEditFormInsertItem dataInsertItem = e.Item as GridEditFormInsertItem;

DropDownList ddlType = dataInsertItem["Type"].Controls[0] as DropDownList;

i used this code in the former radgrid 2.0, but it does not work in th e Q1 grid (formerly prometheus)

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 May 2008, 11:21 AM
Hi Al,

Check out the following help document link.
Customize/Configure GridDropDownColumn

Princy.
0
The KID
Top achievements
Rank 2
answered on 05 Aug 2008, 11:15 PM
What about if the grid is not in edit mode and you're just curious what the value from that database is for that column for that row???????
0
Yavor
Telerik team
answered on 06 Aug 2008, 05:08 AM
Hi Mike,

In this case, you can access the cell, which would correspond to this column in the row, and get the value. It will correspond to the value coming from the database.

Greetings,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Shinu
Top achievements
Rank 2
answered on 06 Aug 2008, 05:09 AM
Hi Mike,

You can try the following code snippet if  want to access the value of the GridDropDownColumn in normal mode.

ASPX:
 <telerik:GridDropDownColumn UniqueName="DropCol"   HeaderText="DropCol"  DataField="ProductName" DataSourceID="SqlDataSource1" ListTextField="ProductName" ListValueField="ProductName"  ></telerik:GridDropDownColumn> 
                         

CS:
  protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            string strTxt = item["DropCol"].Text.ToString(); 
        } 
    } 


Thanks
Shinu.
0
Peter
Top achievements
Rank 1
answered on 12 May 2014, 08:37 AM
This returns the GridDropDownColumn's Text not Value for me. I need the bound value. I think it might be easier to have a hidden GridBoundColumn with the ID I need in addition to the DropDown.
0
Angel Petrov
Telerik team
answered on 15 May 2014, 07:13 AM
Hello Peter,

Could you please elaborate more on in what event you want to extract the value? Note that the drop down becomes available when the item is being opened for edit. That said you can extract its value by subscribing to the OnItemDataBound event of the grid and obtaining a reference to the drop down.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       GridEditableItem editItem = e.Item as GridEditableItem;
       if (editItem != null && editItem.IsInEditMode)
       {
           string value = (editItem["ColumnName"].Controls[0] as DropDownList).SelectedValue;
       }
   }

Additionally you can try obtaining the bound value in read mode by accessing the DataItem.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        GridDataItem item = e.Item as GridDataItem;
        if (item != null)
        {
            string value = ((System.Data.DataRowView)(item.DataItem)).Row["ColumnName"].ToString();
        }
    }


Regards,
Angel Petrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
al
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
The KID
Top achievements
Rank 2
Yavor
Telerik team
Shinu
Top achievements
Rank 2
Peter
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or