In ASP.NET User Control, actually CONSUME the data from DataSourceID, not just pass DataSourceID to child control?

67 views Asked by At

I've been doing ASP.NET webforms for a while, but I'm new to User Controls. Is it possible for a User Control to consume data in the same way that the stock databound controls do, like, for instance, a DropDownList (whose values come from an ObjectDataSource, and are stored in Viewstate after the initial query)? Or must this be done by a Server Control instead?

What I want my User Control to do is to fetch a list of dates from the database (via an ObjectDataSource), find the nearest preceding Saturday to the first record's date, the nearest following Sunday to the last record's date, then programmatically generate and emit some JavaScript code (technically, HTML5 Canvas drawing commands) for my two calculated dates, and all the dates from the data itself. But it only needs to fetch the data once, not on every postback.

In my first draft, I hardcoded a call to the database select function in the User Control's codebehind, just to make sure my Canvas drawing commands were emitted correctly. But I hate to keep this as a long term solution. It was kind of clunky, too, because my User Control is destined to be housed in a FormView. I had to manually call my User Control's update function from the FormView's DataBound event.

I did Google this for several hours, but most articles and discussions revolved around passing the DataSourceID to child controls, not actively consuming data from the DataSourceID. Can it be done?

If the User Control can't natively consume the data, can I give the User Control a child GridView (something I wanted to do anyway), and somehow peek over the GridView's shoulder at ITS copy of the data?

0

There are 0 answers