Dynamic DataGrid Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave Bailey

    #1

    Dynamic DataGrid Problem

    I am trying to dynamically build a DataGrid dynamically.
    The code runs OK but the DataGrid is never built and
    displayed. Can someone look at the following code and see
    if they can determine what I am missing.

    Thanks,

    Dave

    using System;
    using System.Collecti ons;
    using System.Componen tModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.Sess ionState;
    using System.Web.UI;
    using System.Web.UI.W ebControls;
    using System.Web.UI.H tmlControls;
    using System.Data.Ole Db;
    using System.Configur ation;




    namespace Type3CTracking
    {
    /// <summary>
    /// Summary description for detailsForm.
    /// </summary>
    public class workorderDetail sForm :
    System.Web.UI.P age
    {
    protected System.Web.UI.W ebControls.Labe l
    workorderLabel;
    protected System.Web.UI.W ebControls.Labe l
    mrLabel;
    protected
    System.Web.UI.W ebControls.Text Box mrText;
    protected System.Web.UI.W ebControls.Labe l
    prLabel;
    protected
    System.Web.UI.W ebControls.Text Box prText;
    protected System.Web.UI.W ebControls.Labe l
    poLabel;
    protected
    System.Web.UI.W ebControls.Text Box poText;
    protected
    System.Web.UI.W ebControls.Text Box workorderText;
    protected System.Web.UI.W ebControls.Labe l
    wonumLabel;
    protected
    System.Data.Ole Db.OleDbDataAda pter oda;
    protected
    System.Data.Ole Db.OleDbConnect ion dataConnection;
    protected System.Data.Ole Db.OleDbCommand
    dataCommand;
    protected
    System.Data.Ole Db.OleDbDataRea der dataReader;
    protected System.Data.Dat aSet ds = new
    DataSet();
    public DataGrid workorder = new DataGrid();


    private void Page_Load(objec t sender,
    System.EventArg s e)
    {


    string workorder = Request
    ["Workorder"];
    workorderText.T ext = workorder;

    string mr = Request["MR"];
    mrText.Text = mr;

    string pr = Request["PR"];
    prText.Text = pr;

    string po = Request["PO"];
    poText.Text = po;

    CreateDataSourc e();


    }




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

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

    }
    #endregion




    private void CreateDataSourc e()
    {
    string connStr
    = "Provider=\"MSD AORA.1\";User ID=DB1;Data
    Source=DEMO;Pas sword=XXXXXXXX" ;
    string strSelect = "Select Wonum
    from Workorder where Wonum =" + "'" + workorderText.T ext
    + "'";

    oda = new OleDbDataAdapte r
    (strSelect, connStr);
    ds = new DataSet();

    oda.Fill(ds);
    ds.Tables[0].TableName
    = "Workorder" ;

    //make the DataGrid
    workorder = new DataGrid();
    workorder.CellP adding = 2;
    workorder.CellS pacing = 0;
    workorder.Width = 550;
    workorder.Borde rWidth = 1;
    workorder.Borde rColor =
    Color.Black;
    workorder.AutoG enerateColumns =
    false;
    workorder.ForeC olor = Color.Black;
    workorder.Font. Size = 8;
    workorder.Font. Name = "Arial";

    //sets the HeaderStyle
    workorder.Heade rStyle.BackColo r =
    Color.Gold;
    workorder.Heade rStyle.ForeColo r =
    Color.Black;
    workorder.Heade rStyle.Font.Nam e
    = "Arial";
    workorder.Heade rStyle.Font.Siz e =
    9;

    workorder.Heade rStyle.Horizont alAlign =
    HorizontalAlign .Center;

    //sets alternating style

    workorder.Alter natingItemStyle .BackColor =
    Color.Silver;

    workorder.Alter natingItemStyle .ForeColor =
    Color.Black;

    //sets the itemstyle

    workorder.ItemS tyle.Horizontal Align =
    HorizontalAlign .Left;

    //create the bound columns
    BoundColumn Wonum = new BoundColumn
    ();

    Wonum.HeaderTex t = "Wonum";
    Wonum.DataField = "Wonum";

    //add bound columns to datagrid
    workorder.Colum ns.AddAt(0, Wonum);

    //bind the DataDrid
    workorder.DataS ource = ds.Tables
    ["Workorder"];
    workorder.DataB ind();

    }


    }
    }
  • Jerry Negrelli

    #2
    Dynamic DataGrid Problem

    Are you sure that you've defined a client-side
    <asp:DataGrid /> tag with ID="workorder" (case-sensitive)?

    Because you have the "= new DataGrid()" statement in your
    page initialization, the code-behind will execute
    properly. I'll bet if you remove that statement and just
    keep the "protected DataGrid workorder;" part, you'll get
    an "object reference not set to an instance of an object"
    error, which often means you haven't correctly defined a
    client-side component.

    Jerry Negrelli
    Senior Software Engineer
    Data Scientific Corporation

    [color=blue]
    >-----Original Message-----
    >I am trying to dynamically build a DataGrid[/color]
    dynamically.[color=blue]
    >The code runs OK but the DataGrid is never built and
    >displayed. Can someone look at the following code and[/color]
    see[color=blue]
    >if they can determine what I am missing.
    >
    >Thanks,
    >
    >Dave
    >
    >using System;
    >using System.Collecti ons;
    >using System.Componen tModel;
    >using System.Data;
    >using System.Drawing;
    >using System.Web;
    >using System.Web.Sess ionState;
    >using System.Web.UI;
    >using System.Web.UI.W ebControls;
    >using System.Web.UI.H tmlControls;
    >using System.Data.Ole Db;
    >using System.Configur ation;
    >
    >
    >
    >
    >namespace Type3CTracking
    >{
    > /// <summary>
    > /// Summary description for detailsForm.
    > /// </summary>
    > public class workorderDetail sForm :
    >System.Web.UI. Page
    > {
    > protected System.Web.UI.W ebControls.Labe l
    >workorderLabel ;
    > protected System.Web.UI.W ebControls.Labe l
    >mrLabel;
    > protected
    >System.Web.UI. WebControls.Tex tBox mrText;
    > protected System.Web.UI.W ebControls.Labe l
    >prLabel;
    > protected
    >System.Web.UI. WebControls.Tex tBox prText;
    > protected System.Web.UI.W ebControls.Labe l
    >poLabel;
    > protected
    >System.Web.UI. WebControls.Tex tBox poText;
    > protected
    >System.Web.UI. WebControls.Tex tBox workorderText;
    > protected System.Web.UI.W ebControls.Labe l
    >wonumLabel;
    > protected
    >System.Data.Ol eDb.OleDbDataAd apter oda;
    > protected
    >System.Data.Ol eDb.OleDbConnec tion dataConnection;
    > protected System.Data.Ole Db.OleDbCommand
    >dataCommand;
    > protected
    >System.Data.Ol eDb.OleDbDataRe ader dataReader;
    > protected System.Data.Dat aSet ds = new
    >DataSet();
    > public DataGrid workorder = new DataGrid[/color]
    ();[color=blue]
    >
    >
    > private void Page_Load(objec t sender,
    >System.EventAr gs e)
    > {
    >
    >
    > string workorder = Request
    >["Workorder"];
    > workorderText.T ext = workorder;
    >
    > string mr = Request["MR"];
    > mrText.Text = mr;
    >
    > string pr = Request["PR"];
    > prText.Text = pr;
    >
    > string po = Request["PO"];
    > poText.Text = po;
    >
    > CreateDataSourc e();
    >
    >
    > }
    >
    >
    >
    >
    > #region Web Form Designer generated code
    > override protected void OnInit(EventArg s[/color]
    e)[color=blue]
    > {
    > //
    > // CODEGEN: This call is required
    >by the ASP.NET Web Form Designer.
    > //
    > InitializeCompo nent();
    > base.OnInit(e);
    > }
    >
    > /// <summary>
    > /// Required method for Designer support -[/color]
    [color=blue]
    >do not modify
    > /// the contents of this method with the
    >code editor.
    > /// </summary>
    > private void InitializeCompo nent()
    > {
    > this.Load += new
    >System.EventHa ndler(this.Page _Load);
    >
    > }
    > #endregion
    >
    >
    >
    >
    > private void CreateDataSourc e()
    > {
    > string connStr
    >= "Provider=\"MSD AORA.1\";User ID=DB1;Data
    >Source=DEMO;Pa ssword=XXXXXXXX ";
    > string strSelect = "Select Wonum
    >from Workorder where Wonum =" + "'" + workorderText.T ext
    >+ "'";
    >
    > oda = new OleDbDataAdapte r
    >(strSelect, connStr);
    > ds = new DataSet();
    >
    > oda.Fill(ds);
    > ds.Tables[0].TableName
    >= "Workorder" ;
    >
    > //make the DataGrid
    > workorder = new DataGrid();
    > workorder.CellP adding = 2;
    > workorder.CellS pacing = 0;
    > workorder.Width = 550;
    > workorder.Borde rWidth = 1;
    > workorder.Borde rColor =
    >Color.Black;
    > workorder.AutoG enerateColumns =
    >false;
    > workorder.ForeC olor = Color.Black;
    > workorder.Font. Size = 8;
    > workorder.Font. Name = "Arial";
    >
    > //sets the HeaderStyle
    > workorder.Heade rStyle.BackColo r =
    >Color.Gold;
    > workorder.Heade rStyle.ForeColo r =
    >Color.Black;
    > workorder.Heade rStyle.Font.Nam e
    >= "Arial";
    > workorder.Heade rStyle.Font.Siz e =
    >9;
    >
    > workorder.Heade rStyle.Horizont alAlign =
    >HorizontalAlig n.Center;
    >
    > //sets alternating style
    >
    > workorder.Alter natingItemStyle .BackColor =
    >Color.Silver ;
    >
    > workorder.Alter natingItemStyle .ForeColor =
    >Color.Black;
    >
    > //sets the itemstyle
    >
    > workorder.ItemS tyle.Horizontal Align =
    >HorizontalAlig n.Left;
    >
    > //create the bound columns
    > BoundColumn Wonum = new[/color]
    BoundColumn[color=blue]
    >();
    >
    > Wonum.HeaderTex t = "Wonum";
    > Wonum.DataField = "Wonum";
    >
    > //add bound columns to datagrid
    > workorder.Colum ns.AddAt(0, Wonum);
    >
    > //bind the DataDrid
    > workorder.DataS ource = ds.Tables
    >["Workorder"];
    > workorder.DataB ind();
    >
    > }
    >
    >
    > }
    >}
    >.
    >[/color]

    Comment

    • Guest's Avatar

      #3
      Dynamic DataGrid Problem

      Thanks for the suggestion., I dsid figure this out it
      required:

      this.Controls.A dd(MakeWorkorde rGrid());

      in the PageLoad method.

      Thanks,

      Dave

      [color=blue]
      >-----Original Message-----
      >Are you sure that you've defined a client-side
      ><asp:DataGri d /> tag with ID="workorder" (case-sensitive)?
      >
      >Because you have the "= new DataGrid()" statement in your
      >page initialization, the code-behind will execute
      >properly. I'll bet if you remove that statement and just
      >keep the "protected DataGrid workorder;" part, you'll get
      >an "object reference not set to an instance of an object"
      >error, which often means you haven't correctly defined a
      >client-side component.
      >
      >Jerry Negrelli
      >Senior Software Engineer
      >Data Scientific Corporation
      >
      >[color=green]
      >>-----Original Message-----
      >>I am trying to dynamically build a DataGrid[/color]
      >dynamically.[color=green]
      >>The code runs OK but the DataGrid is never built and
      >>displayed. Can someone look at the following code and[/color]
      >see[color=green]
      >>if they can determine what I am missing.
      >>
      >>Thanks,
      >>
      >>Dave
      >>
      >>using System;
      >>using System.Collecti ons;
      >>using System.Componen tModel;
      >>using System.Data;
      >>using System.Drawing;
      >>using System.Web;
      >>using System.Web.Sess ionState;
      >>using System.Web.UI;
      >>using System.Web.UI.W ebControls;
      >>using System.Web.UI.H tmlControls;
      >>using System.Data.Ole Db;
      >>using System.Configur ation;
      >>
      >>
      >>
      >>
      >>namespace Type3CTracking
      >>{
      >> /// <summary>
      >> /// Summary description for detailsForm.
      >> /// </summary>
      >> public class workorderDetail sForm :
      >>System.Web.UI .Page
      >> {
      >> protected System.Web.UI.W ebControls.Labe l
      >>workorderLabe l;
      >> protected System.Web.UI.W ebControls.Labe l
      >>mrLabel;
      >> protected
      >>System.Web.UI .WebControls.Te xtBox mrText;
      >> protected System.Web.UI.W ebControls.Labe l
      >>prLabel;
      >> protected
      >>System.Web.UI .WebControls.Te xtBox prText;
      >> protected System.Web.UI.W ebControls.Labe l
      >>poLabel;
      >> protected
      >>System.Web.UI .WebControls.Te xtBox poText;
      >> protected
      >>System.Web.UI .WebControls.Te xtBox workorderText;
      >> protected System.Web.UI.W ebControls.Labe l
      >>wonumLabel;
      >> protected
      >>System.Data.O leDb.OleDbDataA dapter oda;
      >> protected
      >>System.Data.O leDb.OleDbConne ction dataConnection;
      >> protected System.Data.Ole Db.OleDbCommand
      >>dataCommand ;
      >> protected
      >>System.Data.O leDb.OleDbDataR eader dataReader;
      >> protected System.Data.Dat aSet ds = new
      >>DataSet();
      >> public DataGrid workorder = new DataGrid[/color]
      >();[color=green]
      >>
      >>
      >> private void Page_Load(objec t sender,
      >>System.EventA rgs e)
      >> {
      >>
      >>
      >> string workorder = Request
      >>["Workorder"];
      >> workorderText.T ext = workorder;
      >>
      >> string mr = Request["MR"];
      >> mrText.Text = mr;
      >>
      >> string pr = Request["PR"];
      >> prText.Text = pr;
      >>
      >> string po = Request["PO"];
      >> poText.Text = po;
      >>
      >> CreateDataSourc e();
      >>
      >>
      >> }
      >>
      >>
      >>
      >>
      >> #region Web Form Designer generated code
      >> override protected void OnInit(EventArg s[/color]
      >e)[color=green]
      >> {
      >> //
      >> // CODEGEN: This call is required
      >>by the ASP.NET Web Form Designer.
      >> //
      >> InitializeCompo nent();
      >> base.OnInit(e);
      >> }
      >>
      >> /// <summary>
      >> /// Required method for Designer support -[/color]
      >[color=green]
      >>do not modify
      >> /// the contents of this method with the
      >>code editor.
      >> /// </summary>
      >> private void InitializeCompo nent()
      >> {
      >> this.Load += new
      >>System.EventH andler(this.Pag e_Load);
      >>
      >> }
      >> #endregion
      >>
      >>
      >>
      >>
      >> private void CreateDataSourc e()
      >> {
      >> string connStr
      >>= "Provider=\"MSD AORA.1\";User ID=DB1;Data
      >>Source=DEMO;P assword=XXXXXXX X";
      >> string strSelect = "Select Wonum
      >>from Workorder where Wonum =" + "'" + workorderText.T ext
      >>+ "'";
      >>
      >> oda = new OleDbDataAdapte r
      >>(strSelect, connStr);
      >> ds = new DataSet();
      >>
      >> oda.Fill(ds);
      >> ds.Tables[0].TableName
      >>= "Workorder" ;
      >>
      >> //make the DataGrid
      >> workorder = new DataGrid();
      >> workorder.CellP adding = 2;
      >> workorder.CellS pacing = 0;
      >> workorder.Width = 550;
      >> workorder.Borde rWidth = 1;
      >> workorder.Borde rColor =
      >>Color.Black ;
      >> workorder.AutoG enerateColumns =
      >>false;
      >> workorder.ForeC olor = Color.Black;
      >> workorder.Font. Size = 8;
      >> workorder.Font. Name = "Arial";
      >>
      >> //sets the HeaderStyle
      >> workorder.Heade rStyle.BackColo r =
      >>Color.Gold;
      >> workorder.Heade rStyle.ForeColo r =
      >>Color.Black ;
      >> workorder.Heade rStyle.Font.Nam e
      >>= "Arial";
      >> workorder.Heade rStyle.Font.Siz e =
      >>9;
      >>
      >> workorder.Heade rStyle.Horizont alAlign =
      >>HorizontalAli gn.Center;
      >>
      >> //sets alternating style
      >>
      >> workorder.Alter natingItemStyle .BackColor =
      >>Color.Silve r;
      >>
      >> workorder.Alter natingItemStyle .ForeColor =
      >>Color.Black ;
      >>
      >> //sets the itemstyle
      >>
      >> workorder.ItemS tyle.Horizontal Align =
      >>HorizontalAli gn.Left;
      >>
      >> //create the bound columns
      >> BoundColumn Wonum = new[/color]
      >BoundColumn[color=green]
      >>();
      >>
      >> Wonum.HeaderTex t = "Wonum";
      >> Wonum.DataField = "Wonum";
      >>
      >> //add bound columns to datagrid
      >> workorder.Colum ns.AddAt(0, Wonum);
      >>
      >> //bind the DataDrid
      >> workorder.DataS ource = ds.Tables
      >>["Workorder"];
      >> workorder.DataB ind();
      >>
      >> }
      >>
      >>
      >> }
      >>}
      >>.
      >>[/color]
      >.
      >[/color]

      Comment

      Working...