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

Sample project for RadGrid using DropDown for Edit/Insert

2 Answers 69 Views
Grid
This is a migrated thread and some comments may be shown as answers.
SilverFish
Top achievements
Rank 1
SilverFish asked on 21 Feb 2017, 02:25 PM

I am badly stuck with using DropDown for Edit/Insert in RadGrid. So far I have been successful in displaying data in dropDown inside RadGrid, but not being able to Update to database. While trying to update, I keep getting error:

Telerik.web.UI.GridException "Cannot find a cell bound to a columns name 'XXXX'

Also we cannot use sqldatasource for security purposes. I searched a lot but can't find solution. If someone could provide me with a working code it will be very helpful.

2 Answers, 1 is accepted

Sort by
0
Accepted
Marin Bratanov
Telerik team
answered on 23 Feb 2017, 08:23 AM

Hi,

I am adding here the information we discussed in your support ticket in case anyone else has similar issues.

As a starting point, the following article is important as it explains how to get references to controls and data in grid cells/rows: http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows.

Here are our findings:

  • the error was caused by the different UniqueName of the column. When accessing cells from a column, the UniqueName must be used, not the data field
  • to get the value and not the text, you should use the SelectedValue of the dropdownlist control, not the SelectedItem.Text property

 

Here is how accessing the selected value in the UpdateCommand event should look like:

string FormID = (editedItem["ddlForm"].Controls[0] as DropDownList).SelectedValue;

As for avoiding an SqlDataSource - you seem to have found the solution which is using the ItemDataBound handler to provide a programmatic data source to the dropdowns. Something like (your code with a few modifications to remove data structure):

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        GridEditManager editMan = editedItem.EditManager;
        GridDropDownListColumnEditor editor = editMan.GetColumnEditor("ddlForm") as GridDropDownListColumnEditor;
        DropDownList ddList = editor.DropDownListControl;
        ddList.DataSource = GetDataTable("SELECT [FormID],[FormName] FROM  dbo.[myTable]  WHERE  someColumn= 'someValue'");
        ddList.DataTextField = "FormName";
        ddList.DataValueField = "FormID";
        ddList.DataBind();
 
    }
}


Regards,

Marin Bratanov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
SilverFish
Top achievements
Rank 1
answered on 23 Feb 2017, 04:22 PM
Thanks Marin, both issues were resolved.
Tags
Grid
Asked by
SilverFish
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
SilverFish
Top achievements
Rank 1
Share this question
or