ASP.net drop down dynamically styling and then remembering the styles on aborted submit -


Therefore, I've got an ASP drop down list (this is Net 2.0). I am binding it with data, in fact, when the page loads and the post does not return, we will bring the recorded data, bind all the drop-downs, and set them to their fair value (strictly speaking we say Are: Start the page with basic data set from DB, bind drop down from DB, get actual record data from DB, set down down in the appropriate settings at the moment). What I want to do is selectively styled list options, so the database returns 3 items: the id, text, and a flag show whether I have the record "active" (and I will style it properly). It is very easy to do and I have done it.

My problem occurs when a form submission stops. We've stepped up the page category a little bit and created an AddError () method, which will create a list of errors from the Job Business Rules check, and then display them in legality. It does some work like this, click the Submit button in the event:

  checkbiz rules (); If (Page.IsValid) {SaveData (); }  

If a business rule check fails, the page will not be valid. The problem is, when the page re-provides (the idea is enabled, but there is no data rebound) my beautiful conditional style is now depressed, to stay on the missing socks land. I need to preserve it.

I was hoping to avoid another DB call here (as if the data is getting back from DB, if the page is not valid, then just re-style the list for ). But this is not the end of the world, if it is my caretaker, I was hoping someone could have any alternative suggestions.

How can I better understand this question, if someone has a suggestion or explanation, then do not hesitate to get it, if necessary. ;)

I'm not sure that I fully understand how you are on your drop-down Let's apply the styling items, but it seems that this style is something that is not in addition to control postback. Generally, such information will need to be saved in the viewstate. I see two options (in addition to reloading from DB):

The first method: Create your own drop-down control from the dropdown list. Then, while styling the item, save the style data in the viewstate bag of control:

  public zero settime item {seestate [item.Value] = "active"; }  

Then override the honorer

  Submit safe override zero (HTML textwriters) {foreach (item list in item) {if (ViewState [ Item.Value] == "Active") {** RenderActiveItem **} and {** RenderNormalItem **}}  

Another way: Active IDs will be displayed on each postback Drop-down drop-style using data from viewstate instead of DB


Comments