Extra line in GridView

Discussion in 'ASP .Net Datagrid Control' started by John Doe, Apr 19, 2007.

  1. John Doe

    John Doe Guest

    Why am I am getting an extra line in GridView with the following text in the
    1st column: "System.Web.UI.WebControls.TableRow"


    Here's partial listing of my code:
    ...................
    grid.DataSource = loadTable(ds);
    grid.DataBind();
    ..................
    private DataTable loadTable(DataSet ds)
    {
    DataTable dt = new DataTable();
    DataTable myDataTable = ds.Tables[1];
    int cols = myDataTable.Columns.Count;


    TableHeaderRow thr = new TableHeaderRow();
    for(int i = 0; i < cols; i++)
    {
    TableHeaderCell thc = new TableHeaderCell();
    thc.Text = myDataTable.Columns.ColumnName;
    thr.Cells.Add(thc);

    DataColumn dcol = new DataColumn(thc.Text,
    typeof(System.String));
    dt.Columns.Add(dcol);
    }
    dt.Rows.Add(thr);
    return dt;
    }
    John Doe, Apr 19, 2007
    #1
    1. Advertising

  2. It's most likely an empty row.

    --
    Regards,
    Alvin Bruney
    ------------------------------------------------------
    Shameless author plug
    Excel Services for .NET is coming...
    OWC Black book on Amazon and
    www.lulu.com/owc
    Professional VSTO 2005 - Wrox/Wiley


    "John Doe" <> wrote in message
    news:...
    > Why am I am getting an extra line in GridView with the following text in
    > the 1st column: "System.Web.UI.WebControls.TableRow"
    >
    >
    > Here's partial listing of my code:
    > ..................
    > grid.DataSource = loadTable(ds);
    > grid.DataBind();
    > .................
    > private DataTable loadTable(DataSet ds)
    > {
    > DataTable dt = new DataTable();
    > DataTable myDataTable = ds.Tables[1];
    > int cols = myDataTable.Columns.Count;
    >
    >
    > TableHeaderRow thr = new TableHeaderRow();
    > for(int i = 0; i < cols; i++)
    > {
    > TableHeaderCell thc = new TableHeaderCell();
    > thc.Text = myDataTable.Columns.ColumnName;
    > thr.Cells.Add(thc);
    >
    > DataColumn dcol = new DataColumn(thc.Text,
    > typeof(System.String));
    > dt.Columns.Add(dcol);
    > }
    > dt.Rows.Add(thr);
    > return dt;
    > }
    >
    >
    >
    Alvin Bruney [MVP], Apr 20, 2007
    #2
    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. Replies:
    2
    Views:
    3,909
  2. michael
    Replies:
    0
    Views:
    429
    michael
    Feb 24, 2004
  3. Replies:
    3
    Views:
    672
  4. Some Clown

    One extra line every time...

    Some Clown, Feb 20, 2004, in forum: C++
    Replies:
    8
    Views:
    398
    Hung Tran
    Feb 21, 2004
  5. mathieu
    Replies:
    3
    Views:
    579
    Bo Persson
    Sep 4, 2009
Loading...

Share This Page