Currently I have a drop downlist as follows:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="SelectionHasChanged"
DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="ID"
Width="214px">
/asp:DropDownList>
asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MyDBConnectionString1 %>"
SelectCommand="SELECT [ID], Name], [Name] FROM [Names]">
/asp:SqlDataSource>
There are two things I’m trying to get the list to do when selection is either updated or deleted:
1)Remove deleted contents from DropDownList
2)The first entry in the database is found in the field when the page is loaded, I would like it to either be blank or say “Select”
Currently I need to refress the page to refresh the dropdownlist of deleted items.
I have tried adding DropDownList1.DataBind(); in various methods (page_load, update, delete) and DropDownList1.DataSource = SqlDataSource1; (but I get a message to delete an object of (SqlDataSource1?)
I have added a tag/controll called EnableViewState="false", this refreshs the dropdownlist when I select another item, but when I delete an item I need the list to refresh right away.
1.In order to delete an item from your dropdown list, what you do is to loop through the
ListItemof dropdown list compare the value field (DataValueField) ofListItemitem with the selection that has changed or deleted, remove it from dropdown list if it matches. e.g.:2.Just after binding your dropdownlist, in code behind, add a new
ListItematIndex0, it will solve your problem of displaying “Select” or Blank as a top most selection: