Click here to Skip to main content
15,917,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in my table i have 15 columns i want only 5 columns to display in grid.
i am using following method
gridview1.datasource=dt;
gridview1.databound();
gridview1.columns[1].visible=false;

i am getting the error that index out of range.
Posted
Updated 17-Feb-10 23:09pm
v4

1 solution

The following code will solve your issue.
protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[0].Visible = false;
    }

but take a look at the below code, because it have an advantage, also this hides the column you mentioned & you can get the value from that 1st column at run time. so i prefer this for you.
protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[1].Attributes.Add("style", "display:none");
    }
 
Share this answer
 

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