DarkW1nter
DarkW1nter

Reputation: 2861

.net gridview record count

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.

Upvotes: 1

Views: 521

Answers (4)

Ken
Ken

Reputation: 1880

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

Upvotes: 0

DarkW1nter
DarkW1nter

Reputation: 2861

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

thanks again

Upvotes: 1

Tony Abrams
Tony Abrams

Reputation: 4673

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.

Upvotes: 1

Amit
Amit

Reputation: 7045

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

Upvotes: 0

Related Questions