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

Allow null in GridDropDownColumn inside Radgrid

4 Answers 322 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Derek
Top achievements
Rank 1
Derek asked on 09 Jun 2010, 03:54 PM
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?

4 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 14 Jun 2010, 08:11 AM
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.
0
Alex Vr
Top achievements
Rank 1
answered on 13 Oct 2010, 01:28 PM
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
0
Veli
Telerik team
answered on 18 Oct 2010, 08:13 AM
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
0
Alex Vr
Top achievements
Rank 1
answered on 19 Oct 2010, 09:13 AM
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.
Tags
Grid
Asked by
Derek
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Alex Vr
Top achievements
Rank 1
Veli
Telerik team
Share this question
or