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

2 posts, 0 answers
  1. Katie
    Katie avatar
    1 posts
    Member since:
    Mar 2016

    Posted 22 Dec 2016 Link to this post

    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.      
     }
  2. Eyup
    Admin
    Eyup avatar
    3320 posts

    Posted 27 Dec 2016 Link to this post

    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.
Back to Top