473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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.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();

}
}
}
Nov 15 '05 #1
2 3886
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

-----Original Message-----
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 seeif 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();

}
}
}
.

Nov 15 '05 #2
Thanks for the suggestion., I dsid figure this out it
required:

this.Controls.Add(MakeWorkorderGrid());

in the PageLoad method.

Thanks,

Dave

-----Original Message-----
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

-----Original Message-----
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();

}
}
}
.

.

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
0
by: JP011 | last post by:
Hello I have hit a major road block when it comes to building my dynamic datagrid. To make a long story short I need a dynamic datagrid because my connection string could change and I need the...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
0
by: optimizeit | last post by:
What I am attempting to do is import an Excel Workbook and display the worksheets in a datagrid dynamically. I am very close to getting this to work. I have to this point successfully imported a...
2
by: Shiju Poyilil | last post by:
I have a link button "lButton" created dynamically at the item databound event of the data grid "datagrid1" in the footer.so i want to execute the item command event of the datagrid on clicking...
0
by: tafpin | last post by:
I have an application with a datagrid. In the IDE I have 2 template columns. The first has an image button and the second contains a link button. According to the results that I get back I must...
1
by: benoit | last post by:
Hi, I created a Dynamic Datagrid and i added an EditCommandColumn to it. Works fine, but my Editcommand eventhandler seems to have a problem with PostBack This is my code private DataGrid...
7
by: CanoeGuy | last post by:
I have been trying for the last two weeks to display a dynamic DataGrid. The data that I'm pulling from a SQL Server DB will have whole columns that will be either NULL or 0. I want to display...
4
by: tg | last post by:
Visual Studio 2003 My problem is that I am dynamically creating a datagrid on pageload. The datagrid is completely dynamic as it is based on the number of columns returned from a recordset. The...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.