Drop Down List
-
I have a dropdown list. I bound it to a sqldatasource. It is showing me following items which are in database. App1 App2 App3 But I want that my dropdown list should look like following. How can I get the text --Select Item -- on first index though I attach sqldatasource to dropdown. --Select Item-- App1 App2 App3
-
I have a dropdown list. I bound it to a sqldatasource. It is showing me following items which are in database. App1 App2 App3 But I want that my dropdown list should look like following. How can I get the text --Select Item -- on first index though I attach sqldatasource to dropdown. --Select Item-- App1 App2 App3
Do something like this: dropdownlist.Items.Add(new ListItem("--Select Item--")); dropdownlist.AppendDataBoundItems = true; dropdownlist.datasource = somedatasource; dropdownlist.TextField = "Something"; dropdownlist.ValueField = "somefield"; dropdownlist.DataBind(); Thats all you have to do. Add an item in the list and then set AppendDataBoundItems = true before you bind the list to a data source.