Last post Mar 07, 2012 12:41 PM by superguppie
Mar 05, 2012 06:06 PM|vagabond505|LINK
I have a customer DDL populated from a table. If I remove a cust from the table because that cust is no longer working here and a user edits a record that had that particular customer in it, an error occurs. How can I avoid this?
Mar 05, 2012 06:13 PM|MetalAsp.Net|LINK
Mar 05, 2012 06:19 PM|basheerkal|LINK
If your Udate Query is based on Customer, change it to based on ID or some other field.
Only a wild guess
Mar 05, 2012 06:24 PM|vagabond505|LINK
It needs to exist in the table and DDL or else the error appears. I guess I would have figure a way so that it doesn't appear to the user?
The error being:
'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Mar 05, 2012 06:27 PM|MetalAsp.Net|LINK
Mar 05, 2012 06:48 PM|vagabond505|LINK
Normally I do but there are exceptions where maybe it's not necessary given the type of quest, in this case it's a logic quest. The error is a standard well known one. but if it'll help:
DropDownList1.DataSource = dt;
<asp:DropDownList ID="DropDownList1" runat="server" DataTextField="cust">
Mar 05, 2012 06:53 PM|MetalAsp.Net|LINK
Mar 05, 2012 07:19 PM|vagabond505|LINK
That's the kicker, if I take the customer out of the table and the user edits a record that the customer is in, the error occurs, so I think it has to remain, maybe somehow hide it from the user?
Mar 05, 2012 07:27 PM|MetalAsp.Net|LINK
Mar 05, 2012 07:38 PM|vagabond505|LINK
The records must remain there is true as they need to be worked on. Can you explain about the "logical" delete?
Mar 05, 2012 07:41 PM|MetalAsp.Net|LINK
Mar 05, 2012 08:01 PM|vagabond505|LINK
The boss will be asking me to delete the customer from the list so that users cannot add it to new records. Hence my dilemma.. ;-(
Mar 06, 2012 03:47 PM|superguppie|LINK
Ah, so you can't really delete it, as existing references need to be maintained.
What I usually do in such cases is give the table that needs this behavior a visible column of type bit. The DropDownList should then bind to items that have visible = 1. If an item should no longer be selectable, I just set visible = 0. Existing references
will not be violated. But no new references can be made.
Mar 06, 2012 06:22 PM|vagabond505|LINK
Under your scenario, will it be invisible in the DDL? Would the DDL still look normal?
PS, It still needs to be bound to the DDL or else that error message pops up.
Mar 07, 2012 08:11 AM|Qin Dian Tang - MSFT|LINK
After you delete data in table, you need to rebind or refresh the data in these presentation controls for updating to new data. If you can edit the data for the deleted record, it is already a problem.
Mar 07, 2012 10:25 AM|superguppie|LINK
Hmmmm, overlooked that. What I posted will take it out of the DropDownList.
For records that hold the choice that can not be picked, do you still want to be able to change the value? If not, you could make the field read-only for those records. Then you won't need the DropDownList anymore.
Mar 07, 2012 12:19 PM|vagabond505|LINK
I guess, after some more pondering, is when the record is open for edit, grab the customer from the field into a var, then add it temporarily to the DDL to mitigate the error.
Mar 07, 2012 12:41 PM|superguppie|LINK
That should work. For that row, the customer will be in the DropDownList, though. So it can be picked.
Not sure what the meaning of that would be.