DataGrid trouble please help

Discussion in 'ASP .Net' started by Priya via .NET 247, Aug 9, 2004.

  1. 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

    -----------------------
    Posted by a user from .NET 247 (http://www.dotnet247.com/)

    <Id>+wHipw9twEuzDXwd81iPnw==</Id>
     
    Priya via .NET 247, Aug 9, 2004
    #1
    1. Advertising

  2. Priya via .NET 247

    Scott Allen Guest

    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,

    --
    Scott
    http://www.OdeToCode.com

    On Mon, 09 Aug 2004 08:38:12 -0700, Priya via .NET 247
    <> wrote:

    >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
    >
    >-----------------------
    >Posted by a user from .NET 247 (http://www.dotnet247.com/)
    >
    ><Id>+wHipw9twEuzDXwd81iPnw==</Id>
     
    Scott Allen, Aug 9, 2004
    #2
    1. Advertising

  3. Priya via .NET 247

    Rick Spiewak Guest

    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" <> wrote in message
    news:...
    > 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
    >
    > -----------------------
    > Posted by a user from .NET 247 (http://www.dotnet247.com/)
    >
    > <Id>+wHipw9twEuzDXwd81iPnw==</Id>
     
    Rick Spiewak, Aug 11, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hypo
    Replies:
    6
    Views:
    447
  2. Andrea Maschio
    Replies:
    0
    Views:
    716
    Andrea Maschio
    Dec 5, 2003
  3. Replies:
    4
    Views:
    541
    Chris Uppal
    May 5, 2005
  4. KK
    Replies:
    2
    Views:
    646
    Big Brian
    Oct 14, 2003
  5. MuZZy
    Replies:
    7
    Views:
    1,785
    Mike Hewson
    Jan 7, 2005
Loading...

Share This Page