473,320 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

add datagrid dynamically

Can I add multiple datagrid controls dynamically at runtime?

I want to break up my dataset into separate datagrids, so I can insert a "<p
style="page-break-before: always">
tag between them.

The objective is for the user to be able to print the data with pagebreaks
and column headers on each printed page.

Thanks
Bill
Nov 19 '05 #1
4 2405
Hi Bill,

Yes, you can do exactly what you want to create datagrids at runtime. Here's
a little demo that should get you started. Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto
<form id="Form1" method="post" runat="server">
<P>
<asp:Label id="Label1" runat="server">No. of Grids: </asp:Label>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox></P>
<P>
<asp:Button id="Button1" runat="server" Text="OK"></asp:Button></P>
<P>
<asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder></P>
</form>

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim dg As DataGrid
Dim intCounter As Integer
For intCounter = 0 To _
Convert.ToInt32(TextBox1.Text) - 1
dg = New DataGrid
dg.DataSource = CreateDataSource()
dg.BackColor = _
Color.FromArgb((intCounter * 60), _
intCounter * 20, 255)
dg.DataBind()
PlaceHolder1.Controls.Add(dg)
Next
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"bill" <be****@datamti.com> wrote in message
news:uO**************@TK2MSFTNGP09.phx.gbl...
Can I add multiple datagrid controls dynamically at runtime?

I want to break up my dataset into separate datagrids, so I can insert a
"<p
style="page-break-before: always">
tag between them.

The objective is for the user to be able to print the data with pagebreaks
and column headers on each printed page.

Thanks
Bill


Nov 19 '05 #2
Bill,

Consider using a repeater with a datagrid in the ItemTemplate and a
pagebreak in the Separator Template.

Eliyahu

"bill" <be****@datamti.com> wrote in message
news:uO**************@TK2MSFTNGP09.phx.gbl...
Can I add multiple datagrid controls dynamically at runtime?

I want to break up my dataset into separate datagrids, so I can insert a "<p style="page-break-before: always">
tag between them.

The objective is for the user to be able to print the data with pagebreaks
and column headers on each printed page.

Thanks
Bill

Nov 19 '05 #3
You could add a control dynamically in Page's load method, as follows:

Page.Controls.Add(myGrid)

The control will be added to the end of the page. If you don't want this to
happen, but wish to add a control at a specific point, you have to create a
PlaceHolder control, and add to its controls collection.
in Page load:

PlaceHolder.Controls.Add(myGrid)
and in the page itself:

<asp:PlaceHolder runat="server" id="myPlaceHolder"/>

Hope that helps.
--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"bill" <be****@datamti.com> wrote in message
news:uO**************@TK2MSFTNGP09.phx.gbl...
Can I add multiple datagrid controls dynamically at runtime?

I want to break up my dataset into separate datagrids, so I can insert a "<p style="page-break-before: always">
tag between them.

The objective is for the user to be able to print the data with pagebreaks
and column headers on each printed page.

Thanks
Bill

Nov 19 '05 #4
Now I see how easy it is to add a datagrid dynamically, although the page
break doesn't work.

I added a placeholder control to a panel control - otherwise the new
datagrid was superimposed over the other controls on the page. This works
great.

I then added a literal control with the "<p style='page-break-before:
always'></p>" to the placeholder.

In view-source the page break is in the correct place, but no page break
occurs during printing.

Can I add a page break to a placeholder like this?

Thanks
-bill

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:er*************@TK2MSFTNGP12.phx.gbl...
Hi Bill,

Yes, you can do exactly what you want to create datagrids at runtime. Here's a little demo that should get you started. Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto
<form id="Form1" method="post" runat="server">
<P>
<asp:Label id="Label1" runat="server">No. of Grids: </asp:Label>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox></P>
<P>
<asp:Button id="Button1" runat="server" Text="OK"></asp:Button></P>
<P>
<asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder></P> </form>

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim dg As DataGrid
Dim intCounter As Integer
For intCounter = 0 To _
Convert.ToInt32(TextBox1.Text) - 1
dg = New DataGrid
dg.DataSource = CreateDataSource()
dg.BackColor = _
Color.FromArgb((intCounter * 60), _
intCounter * 20, 255)
dg.DataBind()
PlaceHolder1.Controls.Add(dg)
Next
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"bill" <be****@datamti.com> wrote in message
news:uO**************@TK2MSFTNGP09.phx.gbl...
Can I add multiple datagrid controls dynamically at runtime?

I want to break up my dataset into separate datagrids, so I can insert a
"<p
style="page-break-before: always">
tag between them.

The objective is for the user to be able to print the data with pagebreaks and column headers on each printed page.

Thanks
Bill

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Diego TERCERO | last post by:
Hi... I'm working on a tool for editing text resources for a family of software product my company produces. These text resources are found in a SQL Server database, in a table called...
0
by: sameer mowade via .NET 247 | last post by:
Hello All, I have problem while dynamically removing row from the Datagrid which i have added dynamically as shown in the following code snippet. The problem is that while removing dynamically...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
0
by: optimizeit | last post by:
What I am attempting to do is import an Excel Workbook and display the worksheets in a datagrid dynamically. I am very close to getting this to work. I have to this point successfully imported a...
4
by: dyw55a | last post by:
Donna Mar 15, 10:11 am show options Newsgroups: microsoft.public.dotnet.framework.adonet From: "Donna" <dyw...@yahoo.com> - Find messages by this author Date: 15 Mar 2005 10:11:56 -0800...
2
by: charliewest | last post by:
I am dynamically creating my datagrid, building each column in real-time via code-behind (using c#). The only way i have read to add ImageButtons to my grid dynamically is by creating a separate...
0
by: news.zen.co.uk | last post by:
Hi Guys, Using VB .NET 2003 and ASP1.1, I have a Datagrid embedded in an ASP page. In the processing of the ItemDataBound event I dynamically create a new Datagrid control within the Cell of the...
4
by: gane | last post by:
Hi, I am creating datagrid bound column dynamically and need to check if a datagrid column already exists?Is there a way to check this? thanks gane
3
by: rn5a | last post by:
A SqlDataReader is populated with the records from a SQL Server 2005 DB table. The records retrieved depends upon 2 conditions (the conditions depend on what a user selects in an ASPX page). If...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.