GridView

B

bbawa1

I have a GetData methd which is returning a table using
sqldataadapter. I bound that datasource with GridView but now I want
to invisible Gridview's first column but it gives me following error
although I have 5 columns in my datatable.

Index was out of range. Must be non-negative and less than the size of
the collection.
Parameter name: index

GridView1.DataSource = GetData();

GridView1.DataBind();
GridView1.Columns[1].Visible = false;
Thanks for help me in advance
 
L

lee whitbeck

I have a GetData methd which is returning a table using
sqldataadapter. I bound that datasource with GridView but now I want
to invisible Gridview's first column but it gives me following error
although I have 5 columns in my datatable.

Index was out of range. Must be non-negative and less than the size of
the collection.
Parameter name: index

GridView1.DataSource = GetData();

GridView1.DataBind();
GridView1.Columns[1].Visible = false;
Thanks for help me in advance

What do you get back when you call:

GridView1.Columns.Count();
 
B

bbawa1

I have a GetData methd which is returning a table using
sqldataadapter. I bound that datasource with GridView but now I want
to invisible Gridview's first column but it gives me following error
although I have 5 columns in my datatable.
Index was out of range. Must be non-negative and less than the size of
the collection.
Parameter name: index
GridView1.DataSource = GetData();
GridView1.DataBind();
GridView1.Columns[1].Visible = false;
Thanks for help me in advance

What do you get back when you call:

GridView1.Columns.Count();

Yes. Count = 0 . But I don't know why
 
G

Guest

Hi there,

Autogenerated columns are not included in the Columns collection. You have to
handle RowDataBound event instead:

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow ||
e.Row.RowType == DataControlRowType.Header ||
e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[1].Visible = false;
}
}

hope this helps
--
Milosz


I have a GetData methd which is returning a table using
sqldataadapter. I bound that datasource with GridView but now I want
to invisible Gridview's first column but it gives me following error
although I have 5 columns in my datatable.
Index was out of range. Must be non-negative and less than the size of
the collection.
Parameter name: index
GridView1.DataSource = GetData();
GridView1.DataBind();
GridView1.Columns[1].Visible = false;
Thanks for help me in advance

What do you get back when you call:

GridView1.Columns.Count();

Yes. Count = 0 . But I don't know why
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top