Solved

Help with making column in GridView invisible

Posted on 2011-09-23
5
321 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 500 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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