0

Hi,

I have a gridview with autogenerated fields, 2 template fields, 1 command field. Now, I want to hide one of the columns in a gridview .

I have a code written in rowdatabound

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {

     e.Row.Cells[2].Visible = false;

    }

this code works well when I have not introduced allow paging=true.

but when I have a page indexing property my code for pageindexingchanging is:

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

    {

gridview1.pageindex=e.newpageindex;

 fillgrid();

     }

where fillgrid is a function which is simply binding data coming from data base in gridview.

when I add page indexing to my gridview I get an error:

Specified argument was out of the range of valid values.
Parameter name: index

on this line:

e.Row.Cells[2].Visible = false;

any help shall be appreciated.

thanks
shankbond

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by padtes
0

why not hide the column in fillGrid method?

if (yourCondition) {
   gridview1.Columns[2].Visible = false;
}

See if this works.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.