Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Iterating through records of a DataView with a filter
Message
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00726538
Message ID:
00726561
Views:
17
This message has been marked as the solution to the initial question of the thread.
Hi Doug,

What's happening in your code is you are accessing the rows in the DataTable and not the rows in the DataView in your for loop.

Try this:
for(int myControl = 0; myControl < dv.Count; myControl++)
{
   controlvalue = dv[myControl]["DataINeed"].ToString();
>All,
>
>I have a DataSet which has data that needs conditional processing.
>
>I have the data in a ViewState
>
>DataSet ds = (DataSet)ViewState["Components"];
>DataView dv = new DataView(ds.Tables[0]);
>
>
>The DataSet has 18 records. I then establish a filter
>
>dv.RowFilter = "type <> 'RepeatControl'";
>
>
>And dv.Count is correctly set to 16.
>
>However, if I am processing through my DataView:
>
>for(int myControl = 0; myControl < dv.Count; myControl++)
>{
>   controlvalue = dv.Table.Rows[myControl]["DataINeed"].ToString();
>
>
>But what happens is that I can still access rows of the View which do not meet my filter condition (which happen to be rows 0 and 1 in this case). What do I need to do to make this work correctly? dv.Count is set to 16, but I can still look at dv.Table.Row[16] and dv.Table.Row[17].
>
>I do notice that if I set my filter to
>
>dv.RowFilter = "type = 'RepeatControl'";
>
>dv.Count is set to 2 and I cannot access any data above dv.Table.Row[1]?
>
>Confused,
>Doug
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform