Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help with making column in GridView invisible

Posted on 2011-09-23
5
Medium Priority
?
346 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
  • 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

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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 video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

926 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