Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 728563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:41:44+00:00 2026-05-14T06:41:44+00:00

I have a GridView with 10 columns. On a certain condition, I want to

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:41:45+00:00Added an answer on May 14, 2026 at 6:41 am

    It is checking whether the grid contains your new column (which obviously it won’t; you haven’t added it yet); you actually want to check whether it contains a different column with the same name. Perhaps just loop over the Columns, checking for one with DataField == "DateTimeExpired".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a gridview with certain number of columns and the ID column where
I have a gridview that contains user info and one of the columns is
I have a ListView with a GridView with 3 columns. I want last column
I have a gridview that contains data. I want the user to be able
I have a gridview with couple of columns,I want to achieve the following: If
I have a GridView that has 3 columns: FirstName, LastName and a TemplateField FullName
I have a gridview. Here are my columns: The column choose's control is a
I have a GridView with two columns that have capability to be sorted. After
I have a gridview with 3 columns, only one column is going to be
I have a gridview ...with multiple columns. If I click on one column, it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.