I am attempting to write a custom control. I want to allow its user to specify a DataSourceId (much like GridView, Repeater, etc.).
I can get find the DataSource that corresponds to the id. And I can get the associated DataSourceView. But the only way to get the data out appears to be with an asynchonous Select method. Of course, I can set up the callback such that my code blocks until the callback occurs. But this is requiring so many weird gyrations that I suspect that I am doing something wrong.
If I want a control to function like some of the other ASP.NET data controls, what should I be doing differently?
Here's a bit that I've written:
string dataSourceId = "SomeDataSourceForTesting";
protected override void RenderContents(HtmlTextWriter writer)
{
IDataSource ds = (IDataSource)Parent.FindControl(dataSourceId);
List<string> viewNames = new List<string>();
foreach(string name in ds.GetViewNames())
{
viewNames.Add(name);
}
string viewname = viewNames[0];
writer.WriteLine("the viewname is " + viewname);
DataSourceView view = ds.GetView(viewname);
view.Select(...); //this really has to be asynchronous?
//write out some stuff from the data source
}