views:

38

answers:

4

Hi

IM sure there's an easy way round this....

If I populate a gridview by eg, selecting a value from a dropdown list, then I want to show the total number of records in that gridview, i have a textbox which i set to

    lbTotal.Text = Convert.ToString(gridview.Rows.Count);

Problem is, is only shows the total for what was previously in the gridview, not whats in there currrently.

A: 

Can you please post the code on how you are loading the data using value selected from dropdown. It could be the case that you might not be doing your count again

Amit
A: 

You might want to look into how/where you are doing any databinding to the grid. It seems to me that what's happening is that you are checking the row count before the new databinding is occuring. If that's the case try setting the label/textbox in the BindingContextChanged event of the datagridview.

This is just a guess based on what you have said, posting more information would be useful though :P.

Tony Abrams
+1  A: 

got it, changed the EnableViewState of the gridview to false and the rowcount is picked up for the current recordset

thanks again

DarkWinter
A: 

If you have a BindingSource in between your source DataTable (let's say _dtSource) and the DataGridView, you could just do _dtSource.Count.

Ken