Allow null in GridDropDownColumn inside Radgrid

5 posts, 1 answers
  1. Derek
    Derek avatar
    118 posts
    Member since:
    Oct 2008

    Posted 09 Jun 2010 Link to this post

    Is there a way to use the GridDropDownColumn and not require a value?

    We have a grid that we want to use for editing, but several of the dropdowns don't require a value. If we use the default behaviour, the first entry in the list is automatically selected and saved. We've experimented with including a null value in the datasource, but this generates various errors.

    Is there a simple way to use the dropdown behaviour without requiring a value to be selected?
  2. Answer
    Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 14 Jun 2010 Link to this post

    Hi Derek,

    In order to add an empty item to RadGrid's DropDownColumn you should set EnableEmptyListItem to true and set EmptyListItemText and EmptyListItemValue appropriately.

    All the best,
    Rosen
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Alex Vr
    Alex Vr avatar
    12 posts
    Member since:
    Sep 2005

    Posted 13 Oct 2010 Link to this post

    Hello Derek,

    I'm trying to use GridDropDownColumn with null values.
    I have set the properties to: EnableEmptyListItem="true" EmptyListItemText="NA" EmptyListItemValue="1"
    But the problem is when I try to edit some row it throws JavaScript error:
    Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Editor cannot be initialized for column: BadLeadReasonID

    How can I resolve the issue?

    Best Regards,
    Alex Vr
  5. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 18 Oct 2010 Link to this post

    Hi Alex Vr,

    You are getting a server error. If you disable all AJAX on your page, you will get exception info along with the stack trace that can tell you more about what caused the issue. If the problem persists, send us the stack trace along with your RadGrid definition and related code.

    Greetings,
    Veli
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Alex Vr
    Alex Vr avatar
    12 posts
    Member since:
    Sep 2005

    Posted 19 Oct 2010 Link to this post

    Hello Veli,

    I couldn't recreate the problem but I solved it in little different way.
    When the properties:EnableEmptyListItem="true" EmptyListItemText="NA" EmptyListItemValue="1" where set I had a problem that when I edit the the row and value was null it didn't select automatically the 'NA' in the combobox.
    So I removed all the above properties and only left the ConvertEmptyStringToNull="true" property.
    Aslo I added the following code the the events:

    protected void LeadsRadGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
         .....
      
          if (e.Item is GridEditableItem && e.Item.IsInEditMode)
          {
                GridEditableItem editedItem = e.Item as GridEditableItem;
                ExtraLeadsCL.Database.Lead lead = (ExtraLeadsCL.Database.Lead)e.Item.DataItem;
      
                GridEditManager editMan = editedItem.EditManager;
                GridDropDownListColumnEditor editor = editMan.GetColumnEditor("BadLeadReasonID") as GridDropDownListColumnEditor;
                //editor.ComboBoxControl.Items.Clear();
      
                editor.ComboBoxControl.DataSource = ExtraLeadsCL.Core.BadLeadReason.GetAllBadLeadReasonsDatasource();
                editor.ComboBoxControl.DataTextField = "Title";
                editor.ComboBoxControl.DataValueField = "BadLeadReasonID";
                editor.ComboBoxControl.DataBind();
      
                editor.ComboBoxControl.Items.Add(new RadComboBoxItem("NA", "0"));
      
                if (lead.BadLeadReasonID == null)
                    editor.ComboBoxControl.SelectedValue = "0";
                else
                    editor.ComboBoxControl.SelectedValue = lead.BadLeadReasonID.ToString();
            }
    }

    Best Regards,
    Alex Vr.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017