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

[Solved] Default GridDropDownColumn selected item on new record

3 Answers 136 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gavin
Top achievements
Rank 1
Gavin asked on 25 Sep 2009, 06:01 AM

Hi,

I am trying to set the default value on 3 GridDropDownColumn's in an auto generated edit form.  I have the following code in the grids item event (based on sample code).  The problem is while this works correctly for text based fields the drop down lists are not set.

protected void rgAppointments_ItemCommand(object source, GridCommandEventArgs e)  
{  
  if (e.CommandName == RadGrid.InitInsertCommandName) //"Add new" button clicked  
  {  
    if (ViewState["LAST_APPOINTMENT"] != null)  
    {  
      AppointmentSave lstApp = (AppointmentSave)ViewState["LAST_APPOINTMENT"];  
      e.Canceled = true;  
      //Prepare an IDictionary with the predefined values  
      System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();  
      newValues["staff_member_id"] = lstApp.StaffMember;  
      newValues["appointment_type_id"] = lstApp.AppointmentType;  
      newValues["location_id"] = lstApp.Location;  
      //Insert the item and rebind  
      e.Item.OwnerTableView.InsertItem(newValues);  
    }  
  }  

The version of the controls I am using is 2008.3.1125.20.

How do I get this to work or am I going to have to switch to a template to do this?

Thanks

Gavin

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 25 Sep 2009, 08:58 AM
Hello Gavin,

I also found that the above code does not work with the Q3 2008 versions but it works with the latest version of RadGrid(Q2 2009). You can either upgrade your RadControls from the older version to the latest version, for which you may find the following kb article helpful:
Updating RadControls for ASP.NET to another version or license
(OR)
 You can try out the following code to set a predefined value for the dropdowncolumn when the grid is in edit mode:
c#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted) 
        { 
            GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item;            
            GridEditManager editMan = item.EditManager; 
            GridDropDownListColumnEditor editor = 
            editMan.GetColumnEditor("DropDownColumn1UniqueName"as GridDropDownListColumnEditor;   
            editor.SelectedText = "Text"
        } 
    }  
  } 

-Princy.
0
Gavin
Top achievements
Rank 1
answered on 27 Sep 2009, 10:32 PM

Thanks Princy,  that got it working.

cheers

Gavin.

0
Princy
Top achievements
Rank 2
answered on 29 Sep 2009, 06:45 AM
Hello Gavin,

I'm glad, that helped you out. I believe that the following document would help you understand better about GridDropDownColumns:
Customize/Configure GridDropDownColumn

Regards
-Princy :)
Tags
Grid
Asked by
Gavin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Gavin
Top achievements
Rank 1
Share this question
or