DataGrid trouble please help

  • Thread starter Priya via .NET 247
  • Start date
P

Priya via .NET 247

I am creating an small application to display data from a SQL back end using a stored procedure.

DataGrid1.DataSource = MyService.viewTable();
DataGrid1.DataBind();

I set the property so as not to display a particular Column

DataGrid1.Columns[1].Visible = !DataGrid1.Columns[1].Visible;

It gave me an array out of bound exception. So I displayed the value of the columns and it shows 0. This statement to display the columns is after DataBind. But if just view the table and not make any changes it displays the table.

Could any one tell me what I am doing wrong.

Thanks,
Priya
 
S

Scott Allen

Hi Priya:

If you are using auto-generated columns, I believe the Columns
property does not hold the columns for display. To pull this off
you'll need to set the bound columns for the grid and turn off
autogenerate.

HTH,
 
R

Rick Spiewak

I would just do this differently. Use template columns instead of
autogenerating them, and you can define ahead of time which fields you want.
It's much more flexible than counting columns and cells!

Priya via .NET 247 said:
I am creating an small application to display data from a SQL back end using a stored procedure.

DataGrid1.DataSource = MyService.viewTable();
DataGrid1.DataBind();

I set the property so as not to display a particular Column

DataGrid1.Columns[1].Visible = !DataGrid1.Columns[1].Visible;

It gave me an array out of bound exception. So I displayed the value of
the columns and it shows 0. This statement to display the columns is after
DataBind. But if just view the table and not make any changes it displays
the table.
 

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,770
Messages
2,569,586
Members
45,084
Latest member
HansGeorgi

Latest Threads

Top