Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Multiple Datagrids

Reply
Thread Tools

Multiple Datagrids

 
 
Z3Stealth
Guest
Posts: n/a
 
      12-07-2004
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("<aspataGrid 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
<aspataGrid ...> 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?

 
Reply With Quote
 
 
 
 
aa7im
Guest
Posts: n/a
 
      12-07-2004
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);

 
Reply With Quote
 
 
 
 
Z3Stealth
Guest
Posts: n/a
 
      12-08-2004
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>

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

 
Reply With Quote
 
Z3Stealth
Guest
Posts: n/a
 
      12-08-2004
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>
>
> <aspataGrid 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);
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through multiple Datagrids on page chuckdfoster ASP .Net 1 07-01-2005 05:36 PM
Binding multiple datagrids to the same datasource joe data ASP .Net Datagrid Control 0 04-27-2004 09:51 PM
Export multiple datagrids on web page to Excel Steve Chatham ASP .Net 0 02-24-2004 07:23 PM
Displaying Multiple Datagrids on one page Dennis Davitt ASP .Net Datagrid Control 1 12-30-2003 09:46 PM
Multiple Nested DataGrids Erik ASP .Net Datagrid Control 0 07-16-2003 06:02 PM



Advertisments
 



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