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

RadGrid Auto Generated Edit Mode Drop Down List Selection Not Binding To Database

3 Answers 676 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Katie
Top achievements
Rank 1
Katie asked on 22 Dec 2016, 04:00 PM

I have an auto-generated radgrid bound to a table.  In Edit Mode, in the code-behind, I have successfully created a drop-down list to replace the default a textbox for ONE column.

This drop down list pulls its list items from a second table and data source.  The FAILURE POINT is that the selected item from the drop down list is not SAVED to the subject tablet record.  The other columns will update and save properly.  

The code behind that WORKS for creating the substitute drop-down is here, with my notation as to where I am GUESSING I need to do something correctly.  I have tried every possible forum suggestion, but the source of my pain is that the value in the drop-down list is not being passed to the actual column value on update.  Been stuck for several hours on this one. Probably something silly that I will kick myself for, but not the first time. 

<p></p>protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
 {
     if (e.Item is GridEditableItem && e.Item.IsInEditMode)
     {
         GridEditableItem edit = (GridEditableItem)e.Item;
         edit["EmployeeRecordID"].Visible = false;
                   
  
  
         SqlConnection con = new SqlConnection(MasterConnectionString);
         String queryString = "SELECT GroupLabel From Groups";
         con.Open();            
         SqlDataAdapter dr = new SqlDataAdapter(queryString, con);
         DataTable dt = new DataTable();
         dr.Fill(dt);
         con.Close();
  
         ddledit = (GridEditableItem)e.Item;
         txt = (TextBox)ddledit["GroupAssociation"].Controls[0];
         //txt.Visible = false;                    
         DropDownList droplist = new DropDownList();            
         droplist.DataSource = dt;
         droplist.DataTextField = "GroupLabel";
         droplist.DataValueField = "GroupLabel";
         droplist.DataBind();
         ddledit["GroupAssociation"].Controls.Add(droplist);
         
  
                                
                 
     }
 }
  
 protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
 {
     //this is where I THINK my failure point is, but not sure.      
 }

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 27 Dec 2016, 08:44 AM
Hi Katie,

You can access the GridEditableItem instance directly using e.Item argument and depending on your edit mode you can get the values manually:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-editinsert-mode

In some scenarios, the ExtractValues method can be helpful:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/manual-crud-operations/defaultcs.aspx

If you are using templates, make sure that you are using the Bind expression in the form controls in your :
http://msdn.microsoft.com/en-us/library/vstudio/ms178366(v=vs.100).aspx

Alternatively, you can directly try implementing automatic CRUD operations:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/automatic-crud-operations/defaultcs.aspx

I hope this will prove helpful.


Regards,
Eyup
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
Beryl
Top achievements
Rank 1
answered on 19 Sep 2019, 05:13 PM
I am facing the same issue and none of the links suggested above show how to collect the value from the dropdownlist added after the grid is created.
0
Eyup
Telerik team
answered on 24 Sep 2019, 07:40 AM

Hello Beryl,

 

You can find working samples with RadGrid and DropDownList here:

https://www.telerik.com/forums/how-to-have-dropdownlist-and-textbox-inside-a-radgrid#A9aPQyI5vE-ENWi8clmy6Q

 

If you have a different configuration in your project, you can open a formal support ticket and send us a very basic sample resembling your original scenario. Then, we will be able to provide more specific and accurate suggestions.

 

Regards,
Eyup
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
General Discussions
Asked by
Katie
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Beryl
Top achievements
Rank 1
Share this question
or