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

GridDropDownColumn in EditMode

4 Answers 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Furqan
Top achievements
Rank 1
Furqan asked on 05 Apr 2012, 01:44 PM
In my RadGrid, I am creating columns dynamically in code behind. One column is a GridDropDownColumn which is created as follows.
GridDropDownColumn columnn = new GridDropDownColumn();
TRG.MasterTableView.Columns.Add(columnn);
 
columnn.ListDataMember = "Department";
columnn.DataField = "Id";
columnn.ListTextField = "Name";
columnn.ListValueField = "Id";
columnn.DropDownControlType = GridDropDownColumnControlType.RadComboBox;
columnn.UniqueName = "Department";
columnn.HeaderText = "Department";

ListDataMemeber is set to corresponding table name in DataSet to which the RadGrid is bound.

Now, this column appears fine in as a Bound Column Display mode , and appears as a RadComboBox in Edit Mode, with correct values.

However, the issue is that the "ExtractValuesFromItem" in Radgrid_UpdateCommand doesn't get the value for this GridDropDownColumn.
protected void MyGrid_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    Hashtable NewData = new Hashtable();
    e.Item.OwnerTableView.ExtractValuesFromItem(NewData, (GridEditableItem)e.Item);
}

If there are total 12 columns in my RadGrid, then, there are 11 in "NewData" hashtable, and the GridDropDownColumn's value is missing.

What is the correct way to achieve this?

4 Answers, 1 is accepted

Sort by
0
Accepted
Maria Ilieva
Telerik team
answered on 10 Apr 2012, 08:41 AM
Hello,

Note that normally the ExtractValuesFromItem method is used in the ItemCommand event when performing manual updates as shown in this help topic. Also another option of getting the newly entered values would be to access the controls inside the particular item and get there values manually as shown in this help topic (section "Accessing the value of cells in edit mode").
It will be helpful if you could post the whole page and code behind so we can have a better idea of how you use this code.

All the best,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Furqan
Top achievements
Rank 1
answered on 10 Apr 2012, 10:24 AM
Thanks a lot Telerik team,

I got this resolved by accessing cells manually as shown at http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html.

Thanks
0
Brian
Top achievements
Rank 2
answered on 01 Feb 2016, 12:09 PM
I am running into this as well.  Even though this can be solved manually, I would like to know why it doesn't work with GridDropDownColumn and RadDropDownList.  It seems dropdowns don't get returned with:
     e.Item.OwnerTableView.ExtractValuesFromItem(NewData, (GridEditableItem)e.Item);
0
Brian
Top achievements
Rank 2
answered on 01 Feb 2016, 12:22 PM

Ok, I figured out the difference.  In the edit form template, I was using <%# DataBinder.Eval(Container, "DataItem.SITEID")%> which was being return in the NewData hashtable. Changing it to <%# Bind("SITEID") %> made it work.  Somehow behind the scenes, ExtractValuesFromItem sees the field via the "Bind()".

 

The non-working example:

 <telerik:RadDropDownList ID="rddSiteId" TabIndex="3" runat="server" DataValueField="SITEID" DataTextField="SITENAME" DropDownHeight="300px" DataSourceID="ObjectDataSource_Sites" Style='<%# (Container is GridEditFormInsertItem) ? "": "display:none;" %>' SelectedValue='<%# DataBinder.Eval(Container, "DataItem.SITEID")%>'></telerik:RadDropDownList>

 

The working example:

<telerik:RadDropDownList ID="rddSiteId" TabIndex="3" runat="server" DataValueField="SITEID" DataTextField="SITENAME" DropDownHeight="300px" DataSourceID="ObjectDataSource_Sites" Style='<%# (Container is GridEditFormInsertItem) ? "": "display:none;" %>' SelectedValue='<%# Bind("SITEID") %>'></telerik:RadDropDownList>

Cheers :)

Tags
Grid
Asked by
Furqan
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Furqan
Top achievements
Rank 1
Brian
Top achievements
Rank 2
Share this question
or