Hi,
Note:: It display an error when Allow paging is true and page size is 10. In normal case when Allow Paging is false, there is no error.
My Code of Pageindexing::
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
fillgrid(); // function to bind data
}
I am using below code to hide a column in Gridview. Gridview have one template field(Checkbox) and multiple coulmns. And Auto generated field property is true,remember that there is no bound field.But it display an error.
My code::
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[4].Visible =false;//error generated on this line
}
Error::
Specified argument was out of the range of valid values.
Parameter name: index
Please help me..
Thanks !
Pankaj
Loading

Roei BarRank #1,271 · 1.4K reputationPosted Oct 9, 2009, 2:00 AM EDT
its the column that you hide not the cell
its a column per row on Item_DataBound event
Pankaj Singh92 reputationPosted Oct 9, 2009, 2:08 AM EDT
I have also use below code, but it also generate error.
My code::
protected void GridView1_DataBound(object sender, EventArgs e)
{
GridView1.Columns[4].Visible = false; // Error on this Line
}
Error::
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Help me !
Pankaj
Roei BarRank #1,271 · 1.4K reputationPosted Oct 9, 2009, 2:32 AM EDT
use
e.Row[4].Visible = false;
Pankaj Singh92 reputationPosted Oct 9, 2009, 2:37 AM EDT
I think you should check this code(e.Row[4].Visible = false; ) does not work on DataBound_event.
Pankaj
Sreekanth199 reputationPosted Oct 9, 2009, 2:51 AM EDT
Rajeswari nathan97 reputationPosted Oct 9, 2009, 2:57 AM EDT
I think you have the cell index problem. Can you check how many cells are there means..
index will start from 0..
[0]
[1]
[3]
Or Give me clear error message...
Pankaj Singh92 reputationPosted Oct 9, 2009, 2:59 AM EDT
This code (e.Item.Cells[4].Visible = false;) is not working on both event.
GridView1_DataBound and GridView1_RowDataBound.
Pankaj
Pankaj Singh92 reputationPosted Oct 9, 2009, 3:05 AM EDT
I have no cell index problem. I know well index will start from 0..
[0]
[1]
[2]...
Pankaj
Sreekanth199 reputationPosted Oct 9, 2009, 3:15 AM EDT