Click here to Skip to main content
16,012,116 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i used a gridview in my project where i hide one column at run time
and done paging.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      e.Row.Cells[1].Visible = false;
  }


it show me the error
MSIL
Specified argument was out of the range of valid values.
Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index
Source Error:
Line 108:    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
Line 109:    {
Line 110:        e.Row.Cells[1].Visible = false;
Line 111:    }
Line 112:}




What will i do?
Please help.
Posted
Updated 26-Dec-10 23:59pm
v2

hi do you have 2 item already?

e.Row.Cells[0] ?
e.Row.Cells[1] ?

check it,i guess this is the problem..
 
Share this answer
 
How/Why do you plan to hide a column in a RowDatabound event?

RowDatabound is an event to handle grid at row basis.
For you, simple find the column and hide it. Something like:
myDg.Columns[1].Visible = false;
 
Share this answer
 
Comments
Starlene 27-Dec-10 23:54pm    
if i hide as myDg.Columns[1].Visible = false; then how can i delete the data with the check option.because the column[1] holds the primary key through with a can delete multiple record with check option
Sandeep Mewara 28-Dec-10 1:41am    
I just gave an example of column[1].
Further, you must be knowing which column to hide right? Just hide it. Having a grid column visible false would still let you access the column and cell value on server side when needed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900