Multiple Datagrids

Discussion in 'ASP .Net Web Controls' started by Z3Stealth, Dec 7, 2004.

  1. Z3Stealth

    Z3Stealth Guest

    I am trying to create an app that will be able to grab data from many
    different databases, and combine that data into one page. I do not know at
    design time how many servers I will need to connect to, that information is
    collected at runtime by reading a configuration file. What I want to do is
    display the data from each server in a separate datagrid on my web form. I
    tried to accomplish this by creating an array of DataGrid controls, and
    assigning the data from each server to a different object in the array. I am
    attempting to display the datagrid with the following code:

    <%
    for (int i = 0; i < NumServers; i++)
    {
    Response.Write("<asp:DataGrid ID=\"dgrData[");
    Response.Write("i");
    Response.Write("]\" HorizontalAlign=\"Center\" CellPadding=\"3\"
    Runat=\"server\" /><br>");
    }
    %>

    This approach does not seem to be working, as Response.Write writes the
    <asp:DataGrid ...> tag, and doesn't actually process it to create the
    DataGrid. Is there a way to display DataGrids when I don't know how many
    there will be?
     
    Z3Stealth, Dec 7, 2004
    #1
    1. Advertising

  2. Z3Stealth

    aa7im Guest

    You must add the DataGrid to the Control collection in the page's
    Init() method somthing like:
    DataGrid myDG = new DataGrid();
    Page.Controls.Add(myDG);
     
    aa7im, Dec 7, 2004
    #2
    1. Advertising

  3. Z3Stealth

    Z3Stealth Guest

    Thank you for your reply. I added the code you suggested, and am getting an
    error when the page loads. Now I have the following code:

    <body>
    <script runat="server">
    protected override void OnInit(EventArgs e)
    {
    base.OnInit(e);
    DataGrid[] dgrData;
    Page.Controls.Add(dgrData);
    }
    </script>

    <asp:DataGrid ID="dgrData" HorizontalAlign="Center" CellPadding="3"
    Runat="server" /><br>
    </body>

    The error I am getting is:
    CS1502: The best overloaded method match for
    'System.Web.UI.ControlCollection.Add(System.Web.UI.Control)' has some invalid
    arguments

    "aa7im" wrote:

    > You must add the DataGrid to the Control collection in the page's
    > Init() method somthing like:
    > DataGrid myDG = new DataGrid();
    > Page.Controls.Add(myDG);
    >
    >
     
    Z3Stealth, Dec 8, 2004
    #3
  4. Z3Stealth

    Z3Stealth Guest

    When I comment out the Page.Controls.Add(dgrData), the page loads, but the
    DataGrid is blank. Most likely because it is looking for a DataGrid, and I
    gave it a Datagrid[] array. Is there a way to display a DataGrid[] object?
    I would like to loop through the array and display each DataGrid in the array
    one at a time.


    "Z3Stealth" wrote:

    > Thank you for your reply. I added the code you suggested, and am getting an
    > error when the page loads. Now I have the following code:
    >
    > <body>
    > <script runat="server">
    > protected override void OnInit(EventArgs e)
    > {
    > base.OnInit(e);
    > DataGrid[] dgrData;
    > Page.Controls.Add(dgrData);
    > }
    > </script>
    >
    > <asp:DataGrid ID="dgrData" HorizontalAlign="Center" CellPadding="3"
    > Runat="server" /><br>
    > </body>
    >
    > The error I am getting is:
    > CS1502: The best overloaded method match for
    > 'System.Web.UI.ControlCollection.Add(System.Web.UI.Control)' has some invalid
    > arguments
    >
    > "aa7im" wrote:
    >
    > > You must add the DataGrid to the Control collection in the page's
    > > Init() method somthing like:
    > > DataGrid myDG = new DataGrid();
    > > Page.Controls.Add(myDG);
    > >
    > >
     
    Z3Stealth, Dec 8, 2004
    #4
    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. Steve Chatham
    Replies:
    0
    Views:
    507
    Steve Chatham
    Feb 24, 2004
  2. chuckdfoster

    Loop through multiple Datagrids on page

    chuckdfoster, Jul 1, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    507
    Teemu Keiski
    Jul 1, 2005
  3. Erik

    Multiple Nested DataGrids

    Erik, Jul 16, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    124
  4. Dennis Davitt

    Displaying Multiple Datagrids on one page

    Dennis Davitt, Dec 30, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    382
    Charlie Nilsson [MSFT]
    Dec 30, 2003
  5. joe data

    Binding multiple datagrids to the same datasource

    joe data, Apr 27, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    432
    joe data
    Apr 27, 2004
Loading...

Share This Page