Thursday 23 July 2009

"Select" as first Item in DropDownList

I have a Dropdownlist (ddlShowId), it is binded with the database. I "Select" as the first item, so how do I do it? Here is the solution-

ddlShowId.DataSource = ShowCtlr.GetShows();
ddlShowId.DataTextField = "ShowTime";
ddlShowId.DataValueField = "ShowType";
ddlShowId.DataBind();
ListItem defaultShowItem = new ListItem("--Select--", string.Empty);
defaultShowItem.Selected = true;
ddlShowId.Items.Insert(0, defaultShowItem);

No comments: