3 Replies - 2628 Views - Last Post: 27 May 2010 - 08:58 AM Rate Topic: -----

#1 jellybeannn  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 15-February 10

DataSet not showing in Gridview

Posted 27 May 2010 - 04:30 AM

Can someone please help me, the dataset is not showing in the gridview, the gridview's autoGenerateColumns is set to true.

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            // create the table
            DataSet ds = GetTable();
            outputView.DataSource = ds;
            outputView.DataBind();
        }
    }

    public DataSet GetTable()
    {
        string test = "hfujghreguierhuierhi";
        string test2 = "gfiufgw";

            // headings
        DataSet ds = new DataSet();
        DataTable dt = ds.Tables.Add("Table");
        dt.Columns.Add(new DataColumn("Valuation Date", typeof(string)));
        dt.Columns.Add(new DataColumn("Construction Cash Flow", typeof(string)));

            // fill rows
        DataRow row = dt.NewRow();
        row["Valuation Date"] = test;
        row["Construction Cash Flow"] = test2;

        return ds;
    }



Is This A Good Question/Topic? 0
  • +

Replies To: DataSet not showing in Gridview

#2 demausdauth  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 638
  • Joined: 03-February 10

Re: DataSet not showing in Gridview

Posted 27 May 2010 - 06:04 AM

Your code is essentially correct, you are only missing a couple steps and have some things out of order in your GetTable().

public DataSet GetTable()
    {
        string test = "hfujghreguierhuierhi";
        string test2 = "gfiufgw";

            // headings

        //makes the dataset
        DataSet ds = new DataSet();

        //makes the datatable
        DataTable dt = new DataTable("Table");
        
        //makes and adds the columns to the datatable
        dt.Columns.Add(new DataColumn("Valuation Date", typeof(string)));
        dt.Columns.Add(new DataColumn("Construction Cash Flow", typeof(string)));
      
     
            // fill rows
        //gets an empty row with the schema (columns, column datatypes, etc...) of the datatable
        // at this point the row does not belong to the table it just has the schema of the table
        DataRow row = dt.NewRow();

        //add data to the current new row
        row["Valuation Date"] = test;
        row["Construction Cash Flow"] = test2;

        //now add the row to the datatable
        dt.Rows.Add(row);

        //before returning the dataset the table needs to be added to it
        ds.Tables.Add(dt);

        return ds;
    }



I would also make the suggestion that your column names should not contain spaces, you can always set the Caption property of a DataColumn, and that will display in a datagridview.

     //makes and adds the columns to the datatable
     dt.Columns.Add(new DataColumn("ValuationDate", typeof(string)));
     dt.Columns.Add(new DataColumn("ConstructionCashFlow", typeof(string)));

     dt.Columns["ValuationDate"].Caption = "Valuation Date";
     dt.Columns["ConstructionCashFlow"].Caption = "Construction Cash Flow";



Was This Post Helpful? 1
  • +
  • -

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: DataSet not showing in Gridview

Posted 27 May 2010 - 07:08 AM

Moved to the ASP.Net forum.
Was This Post Helpful? 0
  • +
  • -

#4 erburrell  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 145
  • Joined: 22-December 09

Re: DataSet not showing in Gridview

Posted 27 May 2010 - 08:58 AM

If you are new to using data sets and such, a really good tutorial is located on asp.net at the following link:

http://www.asp.net/d...access-layer-cs

Hope that helps!

Ed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1