how to get the column names from the gridview

Discussion in 'ASP .Net' started by Pradeep, May 31, 2006.

  1. Pradeep

    Pradeep Guest

    hi,
    im having a very peculiar problem. I populate the gridview based on the
    result of a query, and the gridview shows the rows that are returned by
    the query.
    now if i give gridview1.rows.count i get exactly the no of rows in the
    gridview but when i give gridview1.columns.count i always get it as 0
    despite columns being present in the gridview. Does anyone know y this
    happens ?
    Also, i want to get the column names say like age, name, address etc
    from the gridview..how can i do this ?? will
    gridview1.columns.headertext do the job?? (i being an index
    variable)
    bye
    pradeep
    Pradeep, May 31, 2006
    #1
    1. Advertising

  2. In a DataSet, you have access to rows and columns in the manner you
    prescribe. When you paint on the page, the cells/columns (TDs) are inside
    the rows (TRs), as items are ultimately "painted:" as HTML tables. Try
    looking at the cell collection of the header row.

    --
    Gregory A. Beamer

    *************************************************
    Think Outside the Box!
    *************************************************
    "Pradeep" <> wrote in message
    news:...
    > hi,
    > im having a very peculiar problem. I populate the gridview based on the
    > result of a query, and the gridview shows the rows that are returned by
    > the query.
    > now if i give gridview1.rows.count i get exactly the no of rows in the
    > gridview but when i give gridview1.columns.count i always get it as 0
    > despite columns being present in the gridview. Does anyone know y this
    > happens ?
    > Also, i want to get the column names say like age, name, address etc
    > from the gridview..how can i do this ?? will
    > gridview1.columns.headertext do the job?? (i being an index
    > variable)
    > bye
    > pradeep
    >
    Cowboy \(Gregory A. Beamer\), May 31, 2006
    #2
    1. Advertising

  3. Pradeep

    Pradeep Guest

    Hello Cowboy,
    Thanks for giving the hint...
    Gridview1.headerrow.cells.text did the job
    Thank u very much...i was pullin my hair from the morning not knowing
    how to do this..
    thanks again
    Bye
    Pradeep



    Cowboy (Gregory A. Beamer) wrote:
    > In a DataSet, you have access to rows and columns in the manner you
    > prescribe. When you paint on the page, the cells/columns (TDs) are inside
    > the rows (TRs), as items are ultimately "painted:" as HTML tables. Try
    > looking at the cell collection of the header row.
    >
    > --
    > Gregory A. Beamer
    >
    > *************************************************
    > Think Outside the Box!
    > *************************************************
    > "Pradeep" <> wrote in message
    > news:...
    > > hi,
    > > im having a very peculiar problem. I populate the gridview based on the
    > > result of a query, and the gridview shows the rows that are returned by
    > > the query.
    > > now if i give gridview1.rows.count i get exactly the no of rows in the
    > > gridview but when i give gridview1.columns.count i always get it as 0
    > > despite columns being present in the gridview. Does anyone know y this
    > > happens ?
    > > Also, i want to get the column names say like age, name, address etc
    > > from the gridview..how can i do this ?? will
    > > gridview1.columns.headertext do the job?? (i being an index
    > > variable)
    > > bye
    > > pradeep
    > >
    Pradeep, May 31, 2006
    #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. David M. Weprin
    Replies:
    0
    Views:
    418
    David M. Weprin
    Oct 16, 2003
  2. Showjumper
    Replies:
    1
    Views:
    335
    Peter Bromberg [C# MVP]
    Feb 21, 2004
  3. Keith G Hicks
    Replies:
    3
    Views:
    764
    Keith G Hicks
    Feb 18, 2008
  4. swapnil Daingade

    how to get data grid column names

    swapnil Daingade, Aug 6, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    171
    Saravana
    Aug 6, 2003
  5. beanweed

    Get column names dynamically in datalist?

    beanweed, Jun 17, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    324
    beanweed
    Jun 17, 2004
Loading...

Share This Page