jackey
jackey

Reputation: 105

Bind null value to a dropdown list

I am using items from sharepoint list to be binded to a dropdown list. However, I want the first value in the dropdown to be empty. I cannot insert a null value in the sharepoint list item.

Please let me know how can I do it programmatically. Below is the code I am using to bind the list to dropdownlist

   if (Fldname.Contains("xxxxxx"))
            {
                ddllist.DataSource = data.getCode();
                ddllist.DataTextField = "Title";
                ddllist.DataValueField = "Alphabetic_x0020_Code";
                ddllist.DataBind();
                ddllist.SelectedValue = string.Empty;
                ddllist.Width = 120;
            }

Upvotes: 0

Views: 2663

Answers (1)

Illuminati
Illuminati

Reputation: 4619

there has to be something like this. Where 0 is the position you want the new item be - which is the first in this case. Can do this after the databinding.

ddllist.Items.Insert(0 , string.empty);

Upvotes: 1

Related Questions