Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 20th, 2004, 06:07 AM
Registered User
 
Join Date: Mar 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataGrid Error

Hi,
   I am getting following error

System.Web.HttpException: DataGrid with id 'DataGrid2' could not automatically generate any columns from the selected data source


Here is my code

////////////////////////////////////////////////////////////////////
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace DRIVE.Test
{
    /// <summary>
    /// Summary description for DataSet.
    /// </summary>
    public class DataSetTest : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.DataGrid DataGrid2;
        protected System.Web.UI.WebControls.DataGrid DataGrid1;

        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            if(! Page.IsPostBack)
            {
                DataSet ds = new DataSet("MyDataSet");
                DataTable dt = new DataTable("Table1");
                ds.Tables.Add(dt);

                DataColumn c1 = new DataColumn("id",Type.GetType("System.Int32"),"");
                DataColumn c2 = new DataColumn("VendorName", Type.GetType("System.String"),"");

                dt.Columns.Add(c1);
                dt.Columns.Add(c2);

                for(int i = 0; i <10;i++)
                {
                    DataRow dr =dt.NewRow();
                    dr["id"] = i;
                    dr["VendorName"]= "VendorName" + i.ToString();
                    dt.Rows.Add(dr);
                }
                ds.AcceptChanges();
                DataGrid1.DataSource = ds.Tables[0].DefaultView;
                DataGrid1.DataBind();

                //DataTable dt2 = new DataTable("Table2");
                DataTable dt2 = dt.Clone();
                DataRow newRow;
                newRow = dt2.NewRow();
                newRow["id"] = 14;
                newRow["VendorName"] = 774;

                //Note the alternative method for adding rows.
                dt2.Rows.Add(new Object[] { 12, 555 });
                dt2.Rows.Add(new Object[] { 13, 665 });

                ds.Tables.Add("dt2");
                ds.AcceptChanges();
                DataGrid2.DataSource = ds.Tables[1].DefaultView;
                DataGrid2.DataBind();




            }
        }




        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion
    }
}

////////////////////////////////////////////////////////////////////






Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid Error rsm42 ASP.NET 1.0 and 1.1 Basics 0 January 2nd, 2007 02:29 PM
Error in displaying datagrid lamort ASP.NET 1.0 and 1.1 Basics 0 December 1st, 2006 01:02 PM
Datagrid error lily611 General .NET 4 December 8th, 2004 10:00 AM
datagrid paging error RPG SEARCH ASP.NET 1.0 and 1.1 Basics 1 November 9th, 2004 08:29 AM
One Row in DataGrid error petersonginae VB.NET 2002/2003 Basics 2 July 14th, 2004 05:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.