C# Gridview - Checking if a column already exists when adding a new column fails

Posted by Nir on Stack Overflow See other posts from Stack Overflow or by Nir
Published on 2010-04-18T08:21:47Z Indexed on 2010/04/18 8:33 UTC
Read the original article Hit count: 399

Filed under:
|
|

I have a GridView with 10 columns. On a certain condition, I want to add a new column called "Expiration Date". The problem is that when the user presses "Search" again (Postback) the column is added again.
I check before adding the column, to see if it already exists:

BoundField dtExp = new BoundField
                            {DataField = "DateTimeExpired", HeaderText = "Expiration Date", DataFormatString = "{0:d}"};
if (!grid.Columns.Contains(dtExp)){grid.Columns.Add(dtExp);}

But the problem is that even if the column already exists, "Contains" returns false.
What am I doing wrong?

Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about gridview