473,395 Members | 1,443 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,395 software developers and data experts.

How to dynamically add TableRows in asp.net?

Hi everyone,

I was wondering how best to dynamically add rows to an html table in
asp.net. I've been reading up on PlaceHolder controls in .Net, but every
time I add a new control to the collection it scrolls horizontally. I need
a vertical column.

Here's the ASP code I'm trying to port over. I've simplified it a little
for demonstration. Basically just looping through a recordset and adding
rows to a table, one for each record:
<table border="1">

<%if not (adoRecSet.bof and adoRecSet.eof) then
counter = 0
do while not adoRecSet.eof
%>

<tr>
<td>Display Name: <input type="text" width=15
name="<%="txtDisplayName" & counter%>"
value="<%=adoRecSet("tDisplayName")%>"></td>
</tr>

<%
adoRecSet.movenext
counter = counter + 1
loop
End if%>

</table>
I'd like to accomplish the same thing in .Net but can't figure how to do it.
One thought: is it possible to add a table to my PlaceHolder control and
then add rows from there? Thanks for your help.

-Jim
Nov 19 '05 #1
3 1566
hi,

You can chk the folloing link :
http://www.developerfusion.com/show/4410/4/

regards
Subramanian
-----Original Message-----
Hi everyone,

I was wondering how best to dynamically add rows to an html table inasp.net. I've been reading up on PlaceHolder controls in .Net, but everytime I add a new control to the collection it scrolls horizontally. I needa vertical column.

Here's the ASP code I'm trying to port over. I've simplified it a littlefor demonstration. Basically just looping through a recordset and addingrows to a table, one for each record:
<table border="1">

<%if not (adoRecSet.bof and adoRecSet.eof) then
counter = 0
do while not adoRecSet.eof
%>

<tr>
<td>Display Name: <input type="text" width=15
name="<%="txtDisplayName" & counter%>"
value="<%=adoRecSet("tDisplayName")%>"></td>
</tr>

<%
adoRecSet.movenext
counter = counter + 1
loop
End if%>

</table>
I'd like to accomplish the same thing in .Net but can't figure how to do it.One thought: is it possible to add a table to my PlaceHolder control andthen add rows from there? Thanks for your help.

-Jim
.

Nov 19 '05 #2
Example:

<%@ Page Language="C#" %>

<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
AddRow("Name", "Daniel Hendricks");
AddRow("Phone", "555-1212");
AddRow("Location", "Milwaukee, Wisconsin");
}

private void AddRow(string lbl, string val) {
TableCell cell1 = new TableCell();
TableCell cell2 = new TableCell();
cell1.Text = lbl + ": &nbsp;";
//cell1.Width = 130;
cell1.HorizontalAlign = HorizontalAlign.Right;
cell2.Text = val;

TableRow row = new TableRow();
row.Cells.Add(cell1);
row.Cells.Add(cell2);
}
</script>

<html>
<body>

<asp:table runat="server" id="tblDetail" />

</body>
</html>
Jim Bancroft wrote:
Hi everyone,

I was wondering how best to dynamically add rows to an html table in
asp.net. I've been reading up on PlaceHolder controls in .Net, but every time I add a new control to the collection it scrolls horizontally. I need a vertical column.


Daniel M. Hendricks
http://www.danhendricks.com

Nov 19 '05 #3
Thanks guys-- this helps a lot!

-Jim
Nov 19 '05 #4

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

Similar topics

7
by: Tim T | last post by:
Hi, I have the need to use dynamically loaded user controls in a webform page. I have the controls loading dynamically, and that part works fine. this is the code used in a webform to dynamically...
0
by: panik | last post by:
Hi, In a custom UserControl class I'm defining a Table (Structure) and two TableRows(Header,Navigation) I'm adding both rows to the Table like this: Structure.Rows.Add(Header);...
4
by: Rob Meade | last post by:
Hi all, I'm desperately trying to get this to work and I just cant do it - new to ASP.net - probably the reason! I'm using visual studio for this - I have this in the html page : <asp:Table...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web...
1
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a...
7
by: pmclinn | last post by:
I was wondering if it is possible to dynamically create a structure. Something like this: public sub main sql = "Select Col1, Col2 from Table a" dim al as new arraylist al =...
9
by: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related...
2
by: Dica | last post by:
i've got a script that creates a new tablerow + tablecell and appends that to a non dynamically created table control. a new row is added for each recordset returned from my sql statement. within...
4
by: mohaaron | last post by:
I can think of a lot of reasons why this might need to be done but as far as I can tell it's not possible. I've been looking for a way to add HtmlTableRows to a table using a button click for a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.