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();
}
}
}
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();
}
}
}
Comment