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;
}
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);
精彩评论