DataView rows - filtered

M

matt

hello,

so the DataView object is confusing me. i have a dataset of a bunch of
rows, some of white my page needs to filter out before binding. no
problem, i make a new dataview, set a filter and then bind the dv to my
page. ala:

DataView myDV = New DataView(myDS.Tables[0], "Show=1", "ID DESC",
DataViewRowState.CurrentRows);
myRepeater.DataSource = myDV;

....this is cool and it only shows what its supposed to.

however, what confuses me is... when i try to get the first row of my
filtered view, i do this:

someLabel.Text = myDV.Table.Rows[0][0];

....i am getting a row that was filtered out! (the first row happens to
be one i dont want to show). i had thought the DataView was a new
collection of criteria-matching rows. whaaa? guess not.

so i have two questions:

1) how does a DataList/Grid/whatever know to exclude binding filtered
out items
2) how can i call up a single item from *only* the list of
criteria-matching rows?


thanks!
matt
 
G

Guest

Hi,

First of all DataView is not a view of the whole underlying DataSet. But, it
is a view of any single table contained in a DataSet.

If you write some code like this,

someLabel.Text = myDV.Table.Rows[0][0];

this actually fetches data from the underlying DataTable of the dataview.
Hence, you get the unfiltered data.

For getting the filtered data, you can try:

someLabel.Text = myDV[0][0];

The dataview is like a DataTable or an array of rows.

Saravanan K V
 
M

Miha Markic [MVP C#]

hello,

so the DataView object is confusing me. i have a dataset of a bunch of
rows, some of white my page needs to filter out before binding. no
problem, i make a new dataview, set a filter and then bind the dv to my
page. ala:

DataView myDV = New DataView(myDS.Tables[0], "Show=1", "ID DESC",
DataViewRowState.CurrentRows);
myRepeater.DataSource = myDV;

...this is cool and it only shows what its supposed to.

however, what confuses me is... when i try to get the first row of my
filtered view, i do this:

someLabel.Text = myDV.Table.Rows[0][0];

In this way you are accessing DataTable directly.
Instead, you should do something like:
someLabel.Text = myDV[0].Row[0];
 

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

Similar Threads


Top