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

Select empty item in GridDropDownColumn

3 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 24 Sep 2013, 06:12 PM
I have several columns such as the following in a RadGrid with the EditMode set to Batch and EditType set to Row:

<telerik:GridDropDownColumn DataField="Fund" DataSourceID="odsFunds" FilterControlAltText="Filter Fund column"
    HeaderText="Fund" EnableEmptyListItem="True" ConvertEmptyStringToNull="true" EmptyListItemText="" EmptyListItemValue="" ListTextField="Code" ListValueField="Code" SortExpression="Fund" UniqueName="Fund">
    <ColumnValidationSettings>
        <ModelErrorMessage Text="" />
    </ColumnValidationSettings>
    <HeaderStyle HorizontalAlign="Right" />
    <ItemStyle HorizontalAlign="Right" />
</telerik:GridDropDownColumn>

Each of these columns is bound to a nullable field, and displays correctly. However, when I attempt to edit a row, I cannot select the empty item. It automatically selects the first item in the databound list. How do I select an empty item so that I can pass a null value to the database?

3 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 27 Sep 2013, 10:06 AM
Hi Jon,

In order to achieve the required functionality I would suggest you to use GridTemplateColumn with RadComboBox control in it instead of GridDropDownColumn. This will give you an option to bind the RadComboBox control and select empty value.
I hope this helps.

Regards,
Maria Ilieva
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Jon
Top achievements
Rank 1
answered on 27 Sep 2013, 07:21 PM
Hi Maria,

Thank you for the reply. I've changed my column as you suggested. It now looks like this:

<telerik:GridTemplateColumn FilterControlAltText="Filter Fund column"
    HeaderText="Fund" SortExpression="Fund" UniqueName="Fund" DataField="Fund">
    <EditItemTemplate>
        <telerik:RadDropDownList ID="ddlEditFund" runat="server" DataSourceID="odsFunds" DataTextField="Code" DataValueField="Code" AppendDataBoundItems="true">
            <Items>
                <telerik:DropDownListItem />
            </Items>
        </telerik:RadDropDownList>
    </EditItemTemplate>
    <InsertItemTemplate>
        <telerik:RadDropDownList ID="ddlInsertFund" runat="server" DataSourceID="odsFunds" DataTextField="Code" DataValueField="Code" AppendDataBoundItems="true">
            <Items>
                <telerik:DropDownListItem />
            </Items>
        </telerik:RadDropDownList>
    </InsertItemTemplate>
    <ItemTemplate>
        <asp:Label ID="lblFund" runat="server"><%# DataBinder.Eval(Container.DataItem, "Fund") %></asp:Label>
    </ItemTemplate>
    <HeaderStyle HorizontalAlign="Right" />
    <ItemStyle HorizontalAlign="Right" />
</telerik:GridTemplateColumn>

That does correctly preserve the empty value. However, now when I save changes, it's adding the items from the datasource a second time, rather than rebinding. For this particular column, the data is 1, 2, 3, 4. After I save changes, the dropdown displays 1, 2, 3, 4, 1, 2, 3, 4, and so on, for as many times as I have saved changes in the grid. I'm sure I'm missing something simple, but I'm not sure what it is. Do I have to move my databinding to codebehind instead, as in the example here? http://www.telerik.com/help/aspnet-ajax/grid-operations-with-dropdownlist-in-edititemtemplate.html
0
Princy
Top achievements
Rank 1
answered on 01 Oct 2013, 10:36 AM
Hi Jon,

Please set the AppendDataBoundItems="false" for the RadDropDownList.

ASPX:
<telerik:RadDropDownList ID="ddlEditFund" runat="server" AppendDataBoundItems="false" . . . .>
  <Items>
     <telerik:DropDownListItem />
  </Items>
</telerik:RadDropDownList>

Let me know if any concern.

Thanks,
Princy
Tags
Grid
Asked by
Jon
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Jon
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Share this question
or