开发者

Linking bound DropDownLists in ASP.NET

I am writing a website in ASP.NET. I have a DataList which displays all the books in my datatable. For each book I have a button to put the item into edit mode. Each item has a series of fields, like title, author, keywords etc. Amongst those there is a section and a division field, which describe which section and which division within the se开发者_开发技巧ction owns the book.

Here is the problem I have:

The section and division names are stored in two datatables which reference which divisions belong to which section. Logically, the editing template has got two dropdownlists: one for the section and one for the division. I want to be able to limit the choice of divisions in the second dropdownlist based on the section selected in the first list. I'm ok up to here, it's the next bit which is driving me crazy.

If the user changes the section and then for some reason decides to change it back to its original value, I would like the selected division to default back to its original value to avoid it being inadvertently changed.

I have tried to databind the selected value, but that gives the horrible "item not found in list" error when the section is changed to one which does not contain the original division.

Does anyone know how this kind of dependency can be implemented? Many thanks in advance!


Actually it was really stupid, I just sorted it by making a user control containing both dropdownlists. There are two properties in which I store the desired initial values of the dropdownlists, then in the databound event of each dropdownlist I just put a try catch in whcih I attempt to set the selectedvalue of the list, which works nicely as long as the dropdownlist has not been disabled.

In order to set back to the original division value when selecting the section corresponding to the item I just store the value in a hidden field on page load.

As stupid as that really...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜