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();
}
}
} 2 3903
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.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
();
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
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.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
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();
}
} } .
Thanks for the suggestion., I dsid figure this out it
required:
this.Controls.A dd(MakeWorkorde rGrid());
in the PageLoad method.
Thanks,
Dave -----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
-----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.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 ();
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
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.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 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();
}
} } . . This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 header of the datagrid in
the "ItemDataBound" method of the grid. However, once,
they are added in the grid, i seem to lose the event
handler for the same control. Is there anyone who has
tried this before and knows why this is hapenning ??
|
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 datagrid to handle that. First I tried to create my datagrid by leaving the auto-generate columns equal to true. This worked fine except that when my user wants to edit a line I do not want them to edit column 1, only column 2. I could not find a...
|
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 dropdown in UC1
_________________________
1) MainPage_Load
2) User Control_1 Load
|
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 single worksheet into a dataset. I successfully
built a dynamic datagrid. And I did successfully bind it to the
dataset. Then I added the datagrid control to a PlaceHolder. The first
worksheet displays beautifully.
The next step is to allow...
|
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 the dynamicaly created link
button, but when at runtime i click the dymanic created control it disapears
from the datagrid footer and then it doesnt fire the itemcommand event of the
datagrid.
I am pasting below the pieces of my code for your...
| |
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 add more columns to the
datagrid.
This is a sample of how I am adding these colums:
templateColumn = New TemplateColumn
|
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 GridDataLangs(DataTable vDataTable){
DataGrid myGrid = new DataGrid();
myGrid.AutoGenerateColumns = false;
|
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 only the fields that have actual data
in them and either not display or hide the columns that have NULL or 0
values. As an example, one page may need to display a total of 5 columns and
another page may need to display three columns based on the...
|
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 number of columns could change very often.
Within this datagrid that is created, each cell needs to be colored
different colors based on a the value within the cell. For example, if the
number is less than 90, color the cell red, if it is...
|
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 strDataValueField;
string strDataTextField;
public CreateEditItemTemplateDDL(string DDLName,string DataValueField,string
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |