Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help with making column in GridView invisible

Posted on 2011-09-23
5
Medium Priority
?
341 Views
Last Modified: 2012-06-27
Hello,

When I use the code below to set column(1) of my GridView to invisible, I receive the following error:

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Code:

Dim ds As New DataSet
        ds.ReadXml(Server.MapPath("~/App_Data/Country.xml"))
        GridView1.DataSource = ds.Tables(0)
        GridView1.DataBind()
        GridView1.Columns(1).Visible = False


How do I fix this problem?

Thanks,

0
Comment
Question by:vcharles
[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
  • 3
5 Comments
 
LVL 38

Accepted Solution

by:
Tom Beck earned 2000 total points
ID: 36588651
You should do this on the RowCreated event like this:

Protected Sub GridView1_RowCreated(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
            e.Row.Cells(1).Attributes.Add("style", "display:none")
    End Sub
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 36588731
plz check with the colunms u have in data source.
U can check it with
Gridview1.Columns.Count
Count might have only one.
0
 

Author Comment

by:vcharles
ID: 36589861
Hi,
The code works but I need to achieve this by code. I have one grid displaying data from several xml files, the column I need to hide will depend on which xml file is being displayed.

Thanks,

Victor
0
 

Author Comment

by:vcharles
ID: 36589900
Never mind my last post, I will add if statements for different xml files being loaded in the code to hide different columns.

Thanks,

Victor
0
 

Author Closing Comment

by:vcharles
ID: 36589906
Thank You!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

715 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