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

Discussion in 'ASP .Net Web Controls' started by R Reyes, Oct 24, 2005.

  1. R Reyes

    R Reyes Guest

    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 Reyes, Oct 24, 2005
    #1
    1. Advertising

  2. R Reyes

    R Reyes Guest

    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" wrote:

    > 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" <> wrote in message
    > news:...
    > > 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 Reyes, Oct 24, 2005
    #2
    1. Advertising

  3. R Reyes

    R Reyes Guest

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


    "R Reyes" wrote:

    > 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" wrote:
    >
    > > 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" <> wrote in message
    > > news:...
    > > > 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 Reyes, Oct 24, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. titof
    Replies:
    0
    Views:
    576
    titof
    Jul 24, 2003
  2. timmso
    Replies:
    1
    Views:
    575
    Alex Papadimoulis
    Dec 12, 2003
  3. =?Utf-8?B?bXN1aw==?=

    Using one webform to set a value on another webform

    =?Utf-8?B?bXN1aw==?=, Jul 12, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    528
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jul 12, 2006
  4. =?Utf-8?B?Vk1J?=

    Moving value from popup Webform to main Webform?

    =?Utf-8?B?Vk1J?=, Oct 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    625
    GroupReader
    Oct 9, 2006
  5. Luqman
    Replies:
    2
    Views:
    703
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Apr 11, 2007
Loading...

Share This Page