开发者

Databinding and dynamic TabPanel creation

My current task is an ASP.NET page to display the contents of a data object. One of that object's properties is a list of named lists. For opacity's sake let's call it a Company, which has a list of named locations, and each location is associated with (only) a list of employees.

In case it matters, Company has this property implemented like so:

IDictionary<string, IList<Employee>> mEmployeesByLocation;

Each of those lists can display very easily in a GridView. What I think I want is to put the whole thing in a TabContainerand have a separate TabPanel containing each grid. The tabs and grids will be identical to each other, and the name of each tab will be the associated dictionary key.

Is there a good way to do this?

My first thought was to use a Repeater, but you can't put one inside a TabContainer. The parser doesn't know what to do with it there.

So, it looks like I'll have to create the tabs programatically. Fair enough. If at all possible, I want to avoid having to also create the individual grid controls and programatically assign all their properties.

One suggestion I've g开发者_如何学Cotten is to subclass TabPanel and make it work like a user control, containing a GridView and knowing how to pass databinding through to it. I'm not sure how to go about that, though, or if it will even work. I know how to subclass a control, but I don't think something can both act like a TabPanel and contain controls like a user control does.

Thoughts? Input? Better ideas?


No built in support for this control; that is in third party controls but not in the AJAX control toolkit. You would have to load the tabs programmatically, and if the grids are pretty close to the same, use a user control that has the grid (can load the user control through LoadControl method as in http://aspalliance.com/565_Dynamic_Loading_of_ASPNET_User_Controls).

And that way, you can programmably create the UI. You have to be aware that you will probably need to recreate the UI on every page load (more on that here: http://www.asp.net/(S(wnmvzu45umnszm455c1qs522))/learn/ajax-videos/video-286.aspx). Dynamic controls do not get retained across page postbacks. I don't knwo if the tabs would be retained.

HTH.


This whole idea wound up being discarded due to a bug in TabContainer. In the version of the toolkit I'm stuck using, the control cannot properly handle dynamically created tabs across postbacks.

The problem appears to be in LoadControlState and the ActiveTabIndex property. When state is loaded, the container naively tries to set the tab index to whatever it was previously. Since the dynamic tabs have not yet been created at the time of LoadControlState, the loaded index is likely to be invalid. In this case the property throws an ArgumentOutOfRangeException and the containing page blows up.

(I did find a partial workaround, but it prevents LoadControlState from working at all, and wound up being too ugly to bother with.)

Due to complicated office policy reasons I must not upgrade or modify my version of AjaxControlToolkit, but for anyone else who has this error, it was apparently fixed as of last June:
http://www.codeplex.com/AjaxControlToolkit/WorkItem/View.aspx?WorkItemId=15658

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜