c# - find if dropdown value was added dynamically -
Is a value in a dropdown list dynamically added or is there an initial value?
For example.
& asp: dropdown list id = "MyDDL" runat = "server" & gt; & Lt; ASP: ListItem & gt; 1 & lt; / ASP: ListItem & gt; & Lt; ASP: ListItem & gt; 2 & lt; / ASP: ListItem & gt; & Lt; ASP: ListItem & gt; 3 & lt; / ASP: ListItem & gt; & Lt; / ASP: DropDownList & gt; // 1 Private Zero AddExtraItemToList (on postback) {If (some conditions) / / Additional items can be inserted MyDDL.Items.Add ("17") or not; } // Private Zero RemoveExtraItemsFromList () {// Remove any non-default values from the // list on postback ...? }
It is trivial to codify a list of the basic values behind the code behind it, but if you can assume above which values are the initial properties and the viewstate Were born from restoration
The best way to handle this is to keep track of the original values.
< P> Here is a customized version of your code, which stores the original view in the viewstation (you can store them anywhere). The trick is to pull out items in the dropdown before you do any dynamic inserts for new items.
Comments
Post a Comment