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

How to insert blank item in Telerik OpenAccessLinqDataSource programmatically?

1 Answer 169 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Prasad
Top achievements
Rank 1
Prasad asked on 30 Jun 2014, 05:50 AM
I am using Telerik OpenAccessLinqDataSource. I have loaded the records into that and assign its id to dropdownlist. Its working fine. But, now I want to add blank item into it. How can I insert blank item to Telerik OpenAccessLinqDataSource programmatically and pass it to dropdownlist?

1 Answer, 1 is accepted

Sort by
0
Doroteya
Telerik team
answered on 02 Jul 2014, 12:34 PM
Hi Prasad,

To achieve the necessary behavior you  can use the DataBound event of RadDropDownList and in it to add a blank item without inserting it to the datasource at all. For example:

ASPX
<telerik:RadDropDownList runat="server" ID="rDropDownList"
    DataSourceID="oaLinqDataSource" DataTextField="PropertyToDisplay" DataValueField="IDProperty"
    DropDownHeight="200" EnableVirtualScrolling="true"
    OnDataBound="rDropDownList_DataBound">
</telerik:RadDropDownList>
C#
protected void rDropDownList_DataBound(object sender, EventArgs e)
{
    this.rDropDownList.Items.Insert(0, new Telerik.Web.UI.DropDownListItem());
    this.rDropDownList.SelectedIndex = 0;
}

This way after you retrieve the records through the datasource and bind the result to the control, at the top of the list you will have a blank item.

I hope this helps. If you have additional questions, do not hesitate to get back to us.



Regards,
Doroteya
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
Getting Started
Asked by
Prasad
Top achievements
Rank 1
Answers by
Doroteya
Telerik team
Share this question
or