Professional Web Applications Themes

Create User Controls dynamically - ASP.NET Data Grid Control

Howdy, I have a user control that needs to be displayed X amount of times on one page. How is this done? I was thinking of putting it into a datagrid, which would work, but is there a better way? Thanks! -- David Lozzi Web Applications Developer [email]dlozzi(remove-this)delphi-ts.com[/email]...

  1. #1

    Default Create User Controls dynamically

    Howdy,

    I have a user control that needs to be displayed X amount of times on one
    page. How is this done? I was thinking of putting it into a datagrid, which
    would work, but is there a better way?

    Thanks!

    --
    David Lozzi
    Web Applications Developer
    [email]dlozzi(remove-this)delphi-ts.com[/email]




    David Lozzi Guest

  2. #2

    Default RE: Create User Controls dynamically

    Hi David,

    Welcome to ASPNET newsgroup.
    As for dynamically creating UserControl on asp.net web page. In addition to
    using Template DAtaBound control (as DataGrid, Repeater....), we can also
    use Page.LoadControl to load control instance and add them into a certain
    container control on the page. For example:

    ==================
    private void Page_Load(object sender, System.EventArgs e)
    {
    ..........
    for(int i=0;i<1000;i++)
    {
    Control ctrl = Page.LoadControl("~/uc/MyUsercontrol.ascx");
    ctrl.ID = "myuc_" +i;
    MyPanel.Controls.Add(ctrl);
    }
    }


    BTW, dynamically loading lots of usercontrols and adding into page's
    control structure will cause performance issue especially when the
    usercontrol is not simple one.

    Hope helps. Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    --------------------
    | From: "David Lozzi" <DavidLozzinospam.nospam>
    | Subject: Create User Controls dynamically
    | Date: Thu, 13 Oct 2005 01:37:16 -0400
    | Lines: 16
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
    | X-RFC2646: Format=Flowed; Original
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
    | Message-ID: <#qGmvg7zFHA.908tk2msftngp13.phx.gbl>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | NNTP-Posting-Host: c-24-63-42-200.hsd1.ma.comcast.net 24.63.42.200
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5788
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    |
    | Howdy,
    |
    | I have a user control that needs to be displayed X amount of times on one
    | page. How is this done? I was thinking of putting it into a datagrid,
    which
    | would work, but is there a better way?
    |
    | Thanks!
    |
    | --
    | David Lozzi
    | Web Applications Developer
    | [email]dlozzi(remove-this)delphi-ts.com[/email]
    |
    |
    |
    |
    |

    Steven Cheng[MSFT] Guest

  3. #3

    Default RE: Create User Controls dynamically

    Hi David,

    Have you got any further progress on this issue. or does the suggestions in
    my last reply helps a little? If there're anything else we can help, please
    feel free to post here. Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    --------------------
    | X-Tomcat-ID: 178280068
    | References: <#qGmvg7zFHA.908tk2msftngp13.phx.gbl>
    | MIME-Version: 1.0
    | Content-Type: text/plain
    | Content-Transfer-Encoding: 7bit
    | From: [email]stchengonline.microsoft.com[/email] (Steven Cheng[MSFT])
    | Organization: Microsoft
    | Date: Thu, 13 Oct 2005 09:55:44 GMT
    | Subject: RE: Create User Controls dynamically
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | Message-ID: <zo5RVx9zFHA.2352TK2MSFTNGXA01.phx.gbl>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | Lines: 53
    | Path: TK2MSFTNGXA01.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5789
    | NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
    |
    | Hi David,
    |
    | Welcome to ASPNET newsgroup.
    | As for dynamically creating UserControl on asp.net web page. In addition
    to
    | using Template DAtaBound control (as DataGrid, Repeater....), we can also
    | use Page.LoadControl to load control instance and add them into a certain
    | container control on the page. For example:
    |
    | ==================
    | private void Page_Load(object sender, System.EventArgs e)
    | {
    | .........
    | for(int i=0;i<1000;i++)
    | {
    | Control ctrl = Page.LoadControl("~/uc/MyUsercontrol.ascx");
    | ctrl.ID = "myuc_" +i;
    | MyPanel.Controls.Add(ctrl);
    | }
    | }
    |
    |
    | BTW, dynamically loading lots of usercontrols and adding into page's
    | control structure will cause performance issue especially when the
    | usercontrol is not simple one.
    |
    | Hope helps. Thanks,
    |
    | Steven Cheng
    | Microsoft Online Support
    |
    | Get Secure! [url]www.microsoft.com/security[/url]
    | (This posting is provided "AS IS", with no warranties, and confers no
    | rights.)
    |
    | --------------------
    | | From: "David Lozzi" <DavidLozzinospam.nospam>
    | | Subject: Create User Controls dynamically
    | | Date: Thu, 13 Oct 2005 01:37:16 -0400
    | | Lines: 16
    | | X-Priority: 3
    | | X-MSMail-Priority: Normal
    | | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
    | | X-RFC2646: Format=Flowed; Original
    | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
    | | Message-ID: <#qGmvg7zFHA.908tk2msftngp13.phx.gbl>
    | | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | | NNTP-Posting-Host: c-24-63-42-200.hsd1.ma.comcast.net 24.63.42.200
    | | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
    | | Xref: TK2MSFTNGXA01.phx.gbl
    | microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5788
    | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
    | |
    | | Howdy,
    | |
    | | I have a user control that needs to be displayed X amount of times on
    one
    | | page. How is this done? I was thinking of putting it into a datagrid,
    | which
    | | would work, but is there a better way?
    | |
    | | Thanks!
    | |
    | | --
    | | David Lozzi
    | | Web Applications Developer
    | | [email]dlozzi(remove-this)delphi-ts.com[/email]
    | |
    | |
    | |
    | |
    | |
    |
    |

    Steven Cheng[MSFT] Guest

Similar Threads

  1. Dynamically created user controls
    By Denise in forum ASP.NET Building Controls
    Replies: 4
    Last Post: March 16th, 06:55 PM
  2. Dynamically create controls with non-hierarchical IDs
    By Dale in forum ASP.NET Building Controls
    Replies: 1
    Last Post: July 15th, 05:35 PM
  3. dynamically adding user controls
    By Dune in forum ASP.NET Building Controls
    Replies: 6
    Last Post: October 3rd, 03:53 AM
  4. Dynamically create controls from a network directory tree
    By Jereme in forum ASP.NET Building Controls
    Replies: 0
    Last Post: September 26th, 03:41 PM
  5. How do I dynamically create user controls?
    By David J. Berman in forum ASP.NET Building Controls
    Replies: 2
    Last Post: June 30th, 07:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139