DataBind GridView to a DataViewManager in ASP.NET

A

ack95

Simply question
How can I DataBind() a DataViewManager to a GridView in ASP.NET?

Question in Detail
We have a DataSet with relational DataTables (total of 5). We are
generating emails with user specific data, so instead of going back to
the DB for every user, we are getting all data once and filtering on
the DataSet per user (most data overlaps users so this seems like a
good strategy). Our main GridView has child GridView controls that our
bound via CreateChildView(). All is well except for the fact that I
cannot filter on a related DataTable (B) in the DataSet and then
DataBind to related DataTable (A) and the results be filtered due to
the relationship. My only options are 1) using the Select() method on
the DataTable (A) which will not work b/c I cannot bind DataRow[] to a
GridView and 2) setting the RowFilter on DataTable (B)'s DefaultView
then binding DataTable (A)'s DefaultView as this will result in
unfiltered results, making it pointless. So, I have been looking into
the DataViewManager and as I understand it, it is very much like the
DataSet, but for the DataViews instead of DataTables. This is great
because I can simply set the RowFilter on a DataView inside the
DataViewManager (i.e.
ds.DefaultViewManager.DataViewSettings["DataTableName"].RowFilter = "ID
= 100";) and then bind the DataViewManager to the GridView! Oh, if it
were only that easy. I cannot find any good example of how to do this
nor can I get it to work on my own.

This is how it is done in Windows forms:

dataGrid.SetDataBinding(dvm, "DataTableName");



I've tried this in ASP.NET and it was unsuccessful as I receive an
error stating:
"The data source for GridView with id '' did not have any properties or
attributes from which to generate columns. Ensure that your data
source has content.":

gv.DataSource = ds.DefaultViewManager;
gv.DataMember = "DataTableName";
gv.DataBind();


Any help would be greatly appreciated!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top