Wednesday, January 26, 2011

That value is no longer in the Drop Down

Applications and business processes change all the time.  From time to time we have drop down lists of valid values, say for product version, that change.  The valid versions for a given product can change over time as old versions are sunset and no longer deemed valid for new sales.  This causes a problem when looking at historical records since when we load the record we can't default the version from the database into the field since it's no longer in the drop down list of valid values. An error is thrown and the user cannot see the value in the drop down for the field. In this instance we have added the non-valid value to the list when we populate it and display a note to the user that the value is no longer valid.

If Me.ddlKeyVersion.Items.FindByValue(ds.Tables(0).Rows(0).Item("key_version") Is Nothing Then
   Me.ddlKeyVersion.Items.Add(New ListItem(ds.Tables(0).Rows(0).Item("key_version", ds.Tables(0).Rows(0).Item("key_version")))
   Me.ddlKeyVersion.Items.FindByValue(ds.Tables(0).Rows(0).Item("key_version").Selected = True
   Response.Write("<script language=""javascript"">alert('The Version selected is no longer valid, please select a new version from the list.')</script>")

No comments:

Post a Comment