Hello Rolf,
I'm sorry for keep you waiting so long. We just found this problem thread
when reviewing the newsgroup and it seems our internal tool has incorrectly
missed this issue.
I'll continue to help you on this thread. After a overview through the
previous messages, I'd like to confirm you with my understanding on your
question here:
You're developing a custom webserver control which will use "DataSourceID"
to reference a DataSourceControl(just like any other built-in databound
control such as GridView, listbox....), and you're wondering how to get the
list of dataitems from DataSourceControl and construct your control's
output control tree (when perform databinding), correct? If there is
anything I missed, please corret me.
Based on my research, you can consider the two approaches in your custom
webcontrol to retrieve data list from datasource control:
1. ASP.NET 2.0 has already provided a built-in class "DataBoundControl" for
developing webcontrol that will use the new DataSourceControl databinding
model.
#DataBoundControl Class
http://msdn2.microsoft.com/en-us/lib...rols.databound
control.aspx
You just need to derive your control from "DataBoundControl" class, this
class has already implement the "DataSourceID" property and other methods
necessary for querying data from referenced DataSourceControl(such as the
"GetData" and "GetDataSource"), you can directly call them to get data list
from connected datasource control in your own control's code.
Here is another msdn article describing create a custom databound control
through the above super class:
#Developing Custom Data-Bound Web Server Controls for ASP.NET 2.0
http://msdn2.microsoft.com/en-US/library/ms366539.aspx
2. In #1, I mentioned use the "DataBoundControl" super class to make our
custom control directly get the ability to manipulate data from datasource
control. You can also do it your self if you do not want to derive your
control from the DataBoundControl class. In this case, you need to do the
following things in your control's code:
** Use FindControl method to locate the datasourceControl manually,
something like:
================
DataSourceControl dsc = null;
dsc = this.FindControl(this.DataSourceID) as DataSourceControl;
if(dsc == null)
dsc = this.NamingContainer.FindControl(this.DataSourceID )
as DataSourceControl;
if(dsc ==null)
throw exception........
================
** After you get the DataSourceControl, use its "IDataSource" interface to
query the certain DataSourceView in it:
#IDataSource.GetView Method
http://msdn2.microsoft.com/en-us/lib...urce.getview.a
spx
You can use the "GetViewNames" method to get avaialbe views first.
** After you get the DataSourceView, you can use its "ExecuteSelect" method
to query the underlying data(no matter use your connect to SqlDAtaSource or
ObjectDataSource)
#DataSourceView Class
http://msdn2.microsoft.com/en-us/lib...ourceview.aspx
** The DataSourceView's ExecuteSelect method will use asynchornous
pattern(use callback delegate) to return a IEnumerable list of data, you
can use it to construct the control tree in your custom control.
Hope this helps. If you have anything unclear, please feel free to let me
know.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.