I have a Telerik Grid with the following code:
<telerik:GridDropDownColumn DataSourceID="UserSrc" ListTextField="FName" ListValueField="FName"
UniqueName="FName" SortExpression="FName" HeaderText="Assigned To"
DefaultInsertValue="N/A" DataField="FName" DropDownControlType="DropDownList"
AllowVirtualScrolling="true" ShowMoreResultsBox="true" ItemsPerRequest="10">
</telerik:GridDropDownColumn>
In my code I have the following:
protected void ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "Update")
{
My question is how do I get the selected value from the dropdown.
Give a try to this but you need to be in edit mode because when such row is in display mode, the DropDown control is not rendered. Therefore is not databound and you cannot get its DataValues.
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem item = e.Item as GridEditableItem;
string MyValue = (item["FName"].Controls[0] as RadComboBox).SelectedItem.Text;
}
An alternative, if you are not in edit mode, could be to create an hidden column and hold in there the selected value of your dropdown column and retrieve the value from such column.
In this second case you can get the value of the hidden column like this:
protected void ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "Update")
{
GridDataItem item = (GridDataItem)e.Item;
string value = item["MyHiddenColumn"].Text;
}
}
and your hidden column should look like this:
<telerik:GridBoundColumn DataField="FName" UniqueName="MyHiddenColumn" HeaderText="ID" Visible="false">
</telerik:GridBoundColumn>