Hide a GridView Column

If GridView1.Columns(0).Visible = False there will be an error:

Index is out o range.

Solution:

GridView1.DataBind()

If GridView1.Columns.Count > 0 Then

        GridView1.Columns(0).Visible = False

Else

        GridView1.HeaderRow.Cells(0).Visible = False

        For Each gvr As GridViewRow In GridView1.Rows

                gvr.Cells(0).Visible = False

        Next

End If

Advertisements

About Ahmed

Software craftsman, programmer, developer, system/business analyst, DBA and PM.
This entry was posted in ASP.NET, Programming and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s