Solved

Hiding Gridview Columns

Posted on 2006-11-09
2
516 Views
Last Modified: 2012-08-13
I'm attempting to hide certain gridview boundfield and templatefield columns programmatically. The following code that references the column index works to hide a column.

GridView1.Columns(20).Visible = False

Is it possible to reference the gridview column by name (maybe the HeaderText) rather than the index (20)?

Thank you

0
Comment
Question by:mbowling
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Expert Comment

by:muzzy2003
ID: 17906467
No, only by iterating through the columns comparing the names.
0
 
LVL 28

Accepted Solution

by:
mmarinov earned 100 total points
ID: 17906514
Unfortunately you could not do this direct because the GridView.Columns collections does not allow it.
You can write your own method about this

    private sub HideColumnByName(name as string )

        For each column as DataControlField in GridView1.Columns
       
            if column.HeaderText = name then
                column.Visible = false
            end if
        Next
    End sub

Regards
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question