C# only DataGrid for WebForm? EASY QUES!!!

R

R Reyes

Hi,

I am trying to create a C# only website and can't seem to figure out why my
datagrid isn't showing?

All that's in my aspx file is:
<%@ Page Language="C#" AutoEventWireup="false" CodeFile="myPage.aspx.cs"
Inherits="myPage" %>

And in the code-behind I have:
HtmlForm form = new HtmlForm();
form.Controls.Add(dg);
this.Controls.AddAt(0, new LiteralControl(@"<html><head><title>HELLO
WORLD</title></head><body>"));
this.Controls.Add(form);
this.Controls.Add(new LiteralControl(@"</body></html>"));

This should be pretty straight forward HELLO WORLD page. The data is bound
to my datagrid also. I've tried adding the form and datagrid to different
controls in the controls collection to no avail. I am guessing there are
some datagrid properties such as height, width, ID, yada yada I need defined
that are not. Unless, someone knows the cause of this is from something
else???

Well anyway, the datagrid properties are:
// Main properties
dgEmployeeDirectory.ID = "dgEmployeeDirectory";
dgEmployeeDirectory.Height = 500;
dgEmployeeDirectory.Width = 500;
dgEmployeeDirectory.CellPadding = 5;
dgEmployeeDirectory.CellSpacing = 0;
dgEmployeeDirectory.GridLines = GridLines.Both;
dgEmployeeDirectory.BorderColor = Color.Blue;
dgEmployeeDirectory.ShowHeader = true;
dgEmployeeDirectory.SelectedItemStyle.BackColor = Color.Yellow;

// Paging properties
dgEmployeeDirectory.AutoGenerateColumns = false;
dgEmployeeDirectory.AllowPaging = true;
dgEmployeeDirectory.AllowSorting = true;
dgEmployeeDirectory.PageSize = 20;
dgEmployeeDirectory.PagerStyle.HorizontalAlign = HorizontalAlign.Left;
dgEmployeeDirectory.PagerStyle.Mode = PagerMode.NumericPages;
dgEmployeeDirectory.DataKeyField = "EmployeeID";
dgEmployeeDirectory.Visible = true;
dgEmployeeDirectory.Width = Unit.Pixel(768);

I've defined as many as I can...Anyone know what I might be missing? I've
been stumped for a few hours now...

Thanks in advance!
 
R

R Reyes

Oops, didn't realize there was an asp.net form already in there...From my
understanding (probably wrong now that you replied) I thought I was
"creating" the html form using the literal controls (containing
html/head/body tags) and htmlform control (form tag), to which then I can add
the datagrid.

You replied to my last post about viewstate titled "Failed to load
viewstate" saying that I should try to add the controls programatically with
C# and not hardcoded in ASP.NET so, this is my sorry attempt at that solution
and probably misunderstood you...

In short...I really have no idea why I was trying to add an HTML form to an
ASP.NET form. I'm still on the wrong track...and thinking of the wrong
solutions. Sorry about that.

Alvin Bruney - ASP.NET MVP said:
why are you adding an html form inside of the asp.net form?

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



R Reyes said:
Hi,

I am trying to create a C# only website and can't seem to figure out why my
datagrid isn't showing?

All that's in my aspx file is:
<%@ Page Language="C#" AutoEventWireup="false" CodeFile="myPage.aspx.cs"
Inherits="myPage" %>

And in the code-behind I have:
HtmlForm form = new HtmlForm();
form.Controls.Add(dg);
this.Controls.AddAt(0, new LiteralControl(@"<html><head><title>HELLO
WORLD</title></head><body>"));
this.Controls.Add(form);
this.Controls.Add(new LiteralControl(@"</body></html>"));

This should be pretty straight forward HELLO WORLD page. The data is bound
to my datagrid also. I've tried adding the form and datagrid to different
controls in the controls collection to no avail. I am guessing there are
some datagrid properties such as height, width, ID, yada yada I need defined
that are not. Unless, someone knows the cause of this is from something
else???

Well anyway, the datagrid properties are:
// Main properties
dgEmployeeDirectory.ID = "dgEmployeeDirectory";
dgEmployeeDirectory.Height = 500;
dgEmployeeDirectory.Width = 500;
dgEmployeeDirectory.CellPadding = 5;
dgEmployeeDirectory.CellSpacing = 0;
dgEmployeeDirectory.GridLines = GridLines.Both;
dgEmployeeDirectory.BorderColor = Color.Blue;
dgEmployeeDirectory.ShowHeader = true;
dgEmployeeDirectory.SelectedItemStyle.BackColor = Color.Yellow;

// Paging properties
dgEmployeeDirectory.AutoGenerateColumns = false;
dgEmployeeDirectory.AllowPaging = true;
dgEmployeeDirectory.AllowSorting = true;
dgEmployeeDirectory.PageSize = 20;
dgEmployeeDirectory.PagerStyle.HorizontalAlign = HorizontalAlign.Left;
dgEmployeeDirectory.PagerStyle.Mode = PagerMode.NumericPages;
dgEmployeeDirectory.DataKeyField = "EmployeeID";
dgEmployeeDirectory.Visible = true;
dgEmployeeDirectory.Width = Unit.Pixel(768);

I've defined as many as I can...Anyone know what I might be missing? I've
been stumped for a few hours now...

Thanks in advance!
 
R

R Reyes

Fixed this myself. Basically I just had to remove all the datagrid property
code that i was presetting. Once removed the datagrid showed.

Removed all that looks like this...
R Reyes said:
Oops, didn't realize there was an asp.net form already in there...From my
understanding (probably wrong now that you replied) I thought I was
"creating" the html form using the literal controls (containing
html/head/body tags) and htmlform control (form tag), to which then I can add
the datagrid.

You replied to my last post about viewstate titled "Failed to load
viewstate" saying that I should try to add the controls programatically with
C# and not hardcoded in ASP.NET so, this is my sorry attempt at that solution
and probably misunderstood you...

In short...I really have no idea why I was trying to add an HTML form to an
ASP.NET form. I'm still on the wrong track...and thinking of the wrong
solutions. Sorry about that.

Alvin Bruney - ASP.NET MVP said:
why are you adding an html form inside of the asp.net form?

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



R Reyes said:
Hi,

I am trying to create a C# only website and can't seem to figure out why my
datagrid isn't showing?

All that's in my aspx file is:
<%@ Page Language="C#" AutoEventWireup="false" CodeFile="myPage.aspx.cs"
Inherits="myPage" %>

And in the code-behind I have:
HtmlForm form = new HtmlForm();
form.Controls.Add(dg);
this.Controls.AddAt(0, new LiteralControl(@"<html><head><title>HELLO
WORLD</title></head><body>"));
this.Controls.Add(form);
this.Controls.Add(new LiteralControl(@"</body></html>"));

This should be pretty straight forward HELLO WORLD page. The data is bound
to my datagrid also. I've tried adding the form and datagrid to different
controls in the controls collection to no avail. I am guessing there are
some datagrid properties such as height, width, ID, yada yada I need defined
that are not. Unless, someone knows the cause of this is from something
else???

Well anyway, the datagrid properties are:
// Main properties
dgEmployeeDirectory.ID = "dgEmployeeDirectory";
dgEmployeeDirectory.Height = 500;
dgEmployeeDirectory.Width = 500;
dgEmployeeDirectory.CellPadding = 5;
dgEmployeeDirectory.CellSpacing = 0;
dgEmployeeDirectory.GridLines = GridLines.Both;
dgEmployeeDirectory.BorderColor = Color.Blue;
dgEmployeeDirectory.ShowHeader = true;
dgEmployeeDirectory.SelectedItemStyle.BackColor = Color.Yellow;

// Paging properties
dgEmployeeDirectory.AutoGenerateColumns = false;
dgEmployeeDirectory.AllowPaging = true;
dgEmployeeDirectory.AllowSorting = true;
dgEmployeeDirectory.PageSize = 20;
dgEmployeeDirectory.PagerStyle.HorizontalAlign = HorizontalAlign.Left;
dgEmployeeDirectory.PagerStyle.Mode = PagerMode.NumericPages;
dgEmployeeDirectory.DataKeyField = "EmployeeID";
dgEmployeeDirectory.Visible = true;
dgEmployeeDirectory.Width = Unit.Pixel(768);

I've defined as many as I can...Anyone know what I might be missing? I've
been stumped for a few hours now...

Thanks in advance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top