Reputation: 38
I have an ASP .NET(4.0) web app. The web app has a form view that contains a drop down list. The drop down list is populated like so:
<asp:DropDownList ID="ddlStaff" runat="server"
DataSourceID="StaffDatasource" DataTextField="StaffName"
DataValueField="StaffName" AppendDataBoundItems="True"
SelectedValue='<%# Bind("Staff") %>' >
<asp:ListItem Value=""></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="StaffDatasource" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="*****">
</asp:SqlDataSource>
The staff list is constantly changing so the issue is that SelectedValue throws an error because that staff member does not exist anymore.
I know you can check if the item exists in the list and catch the exception. What I would like to know is if there is a way to display the "non-existing" staff member in the drop down list if they do not exists? Although the name is not listed the staff name is stored with the record. The reason I want to do this is because the users will need to see who was assigned to that record even if they are not there anymore.
EDIT: More details
This how the users would like for it to work.
If it's possible to do this then I can let them know and I'll have it select null when the exception is thrown.
Upvotes: 1
Views: 221
Reputation: 38
If the member is not on the list he isn't present. Why would you want that behaviour? Does the user need old members?
You could create a list with all members old and new ones - but you will have to code the list not declaring. You cannot do it with source controls. You can simply provide a collection to use as the datasource.
Hope this helped a bit.
Upvotes: 1