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.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.OleDb;
using System.Configuration;
namespace Type3CTracking
{
/// <summary>
/// Summary description for detailsForm.
/// </summary>
public class workorderDetailsForm :
System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label
workorderLabel;
protected System.Web.UI.WebControls.Label
mrLabel;
protected
System.Web.UI.WebControls.TextBox mrText;
protected System.Web.UI.WebControls.Label
prLabel;
protected
System.Web.UI.WebControls.TextBox prText;
protected System.Web.UI.WebControls.Label
poLabel;
protected
System.Web.UI.WebControls.TextBox poText;
protected
System.Web.UI.WebControls.TextBox workorderText;
protected System.Web.UI.WebControls.Label
wonumLabel;
protected
System.Data.OleDb.OleDbDataAdapter oda;
protected
System.Data.OleDb.OleDbConnection dataConnection;
protected System.Data.OleDb.OleDbCommand
dataCommand;
protected
System.Data.OleDb.OleDbDataReader dataReader;
protected System.Data.DataSet ds = new
DataSet();
public DataGrid workorder = new DataGrid();
private void Page_Load(object sender,
System.EventArgs e)
{
string workorder = Request
["Workorder"];
workorderText.Text = workorder;
string mr = Request["MR"];
mrText.Text = mr;
string pr = Request["PR"];
prText.Text = pr;
string po = Request["PO"];
poText.Text = po;
CreateDataSource();
}
#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
private void CreateDataSource()
{
string connStr
= "Provider=\"MSDAORA.1\";User ID=DB1;Data
Source=DEMO;Password=XXXXXXXX";
string strSelect = "Select Wonum
from Workorder where Wonum =" + "'" + workorderText.Text
+ "'";
oda = new OleDbDataAdapter
(strSelect, connStr);
ds = new DataSet();
oda.Fill(ds);
ds.Tables[0].TableName
= "Workorder";
//make the DataGrid
workorder = new DataGrid();
workorder.CellPadding = 2;
workorder.CellSpacing = 0;
workorder.Width = 550;
workorder.BorderWidth = 1;
workorder.BorderColor =
Color.Black;
workorder.AutoGenerateColumns =
false;
workorder.ForeColor = Color.Black;
workorder.Font.Size = 8;
workorder.Font.Name = "Arial";
//sets the HeaderStyle
workorder.HeaderStyle.BackColor =
Color.Gold;
workorder.HeaderStyle.ForeColor =
Color.Black;
workorder.HeaderStyle.Font.Name
= "Arial";
workorder.HeaderStyle.Font.Size =
9;
workorder.HeaderStyle.HorizontalAlign =
HorizontalAlign.Center;
//sets alternating style
workorder.AlternatingItemStyle.BackColor =
Color.Silver;
workorder.AlternatingItemStyle.ForeColor =
Color.Black;
//sets the itemstyle
workorder.ItemStyle.HorizontalAlign =
HorizontalAlign.Left;
//create the bound columns
BoundColumn Wonum = new BoundColumn
();
Wonum.HeaderText = "Wonum";
Wonum.DataField = "Wonum";
//add bound columns to datagrid
workorder.Columns.AddAt(0, Wonum);
//bind the DataDrid
workorder.DataSource = ds.Tables
["Workorder"];
workorder.DataBind();
}
}
}