adding html table columns from SQL table rows

I want to put data from an SQL table into an HTML table, but I want to start a new row in the HTML table when it is 5 columns wide.  I have done this in classic ASP with the following code:

TABLE NAME
How can I accomplish the same thing with asp.net? I have created my SqlDataSource and the SelectCommand no problem, but I'm kind of stuck how to loop through the recordset.
0
madala
4/22/2008 10:40:18 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

6 Replies
1112 Views

Similar Articles

[PageSpeed] 53
Get it on Google Play
Get it on Apple App Store

Why do you want to do it manally? Data binding is for such purposes only. Fill a DataSet or DataTable with the SqlCommand and do: GridView.DataSource = DataSet.Tables[0]; GridView.DataBind(); See if this helps: http://msconline.maconstate.edu/Tutorials/ASPNET2/ASPNET09/aspnet09-01.aspx

 


Mark replies as answers if they helped you solve the problem.
0
siva_sm
4/22/2008 11:46:50 AM

Actually, what I'm trying to accomplish is putting a field from each row of the table into a column of the HTML table.  When the number of columns is 5, then I want to start a new row in the HTML table.  Simple data binding works fine when you want to add a row from a table to a row in an HTML table, but not so well with columns.

For example, if my database table has 7 rows like this:

Field1

1

2

3

4

5

6

7

 

Then I want my HTML table to look like this:

1  2  3  4  5

6  7

1
madala
4/22/2008 12:08:31 PM

Hi

plz. use code somethng like this. it'll be helpfull.

HtmlTable htmlTbl = new HtmlTable();

HtmlTableRow row = new HtmlTableRow();

HtmlTableCell tblCell = new HtmlTableCell();HtmlButton inputButton = new HtmlButton();

tblCell.Controls.Add(inputButton);

in case of any query , plz. let me know.

Thankx.

0
rajiv
4/22/2008 12:15:39 PM

This is my original asp code. It's fairly straight forward.  I just get a row from the recordset and put it in a column in the html table, when I reach 5 columns, I start a new row in the HTML table.  I would like to do this with asp.net

<% items = 0 %>
<%rs.movefirst %>
<table><tr>
    <%do while not rs.eof%>
        <TD><%=rs.fields("link")%></TD>
        <% rs.movenext
        items = items + 1
        if items = 5 Then %>
           </TR>
           <TR>
           <% items = 0 %>
      <% end if
    loop%>
 </table>

0
madala
4/22/2008 1:05:41 PM

Hi madala,

Why not use DataList control in ASP.Net. It is exactly what you want to present.

Here is a link of using DataList control: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/datalist.aspx

What you only need to do is to set RepeatDirection as Horizontal and RepeatColumns as five.

Thanks,


Qin Dian Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Qin
4/24/2008 9:25:53 AM
Thanks Qin Dian Tan. That's exactly what I was looking for. I knew there was an easy way to do it.
0
madala
4/24/2008 11:01:14 AM
Reply:

Similar Artilces:

masterpage and control formatting (table control, HTML table control)
I have a master page that contains 1 contentplaceholder.  In my default.aspx (that uses the masterpage layout) I have a table server control.  During page_load I get the data I need and repeatedly add the usercontrol to the table control, one user control per row.  My user control is basically a HTML table with several rows and columns that's populated with data upon creation. I want this table to fill the contentplaceholder's width. In addition within the masterpage I have a CSS link for my stylesheet. Here are my questions: Is there a better way of adding ...

HTML Table (dynamically adding rows/columns)
I can create dynamically rows/cells for a Table WebControl. Is this also possible with an HTML Table (I gave the HTML table an id in the html code)? But intellisense doesn't show this id when trying to access it from my code behind file. thx     It you want to do it with an HTML Table (versus a Table WebControl), you'd probably want to look at client-side script to do that.  Another option server-side would be generate all of your HTML table code server side and then write it down to something like a Literal control.The Universe has no center and I am it. The superior m...

adding / deleting table rows, and accessing controls within added rows
Hi everyone,I would like to know what is a good and simple way to achieve this using asp.net.  Basically i would like the ability to add and delete rows, preferably table rows.  Against each row is its delete button, hitting it will delete the corresponding row.  There is only 1 Add button to add a new row.  In each row, there are say 2 textboxes.  When i hit, say a calculate button, i wish to be able to access all the available textboxes in all the available rows in the event handler, and say just output a sum.If GridView is suggested, could you please explain why i...

Manipulating html table adding removing rows and columns
hello, I want to add/remove rows and columns to a table.  Currently i can add rows and columns but everytime it rewrites the changes made to the table last time. I can not add rows on top of rows.Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.ClickDim rows, cells, j, i rows = 3 cells = 2 'Dim textbox As TextBoxFor j = 0 To rows - 1 Dim r As New HtmlTableRow()For i = 0 To cells - 1 Dim c As New HtmlTableCell()c.Controls.Add(New TextBox) r.Cells.Add(c) Next Table1.Rows.Add(r) Next End Sub This is because Table1 remembe...

How can I speed up alter table when adding identity column to a 20 million row table?
Hi, I have a table with 20 million rows that I have repeatedly tried to add a numeric(10,0) identity column to, but this operation has repeatedly taken up all the space in that db's log. The db has trunc log on chkpt set true, so it looks to me like the alter table statement is treated as one very large transaction. This one transaction apparently runs for a very long time and prevents a checkpoint from occurring and truncating the log. So far the only solution to the filled log problem I can come up with is to make the log bigger and try again. Any other ideas? Also, wha...

Convert a html table control to a Table Web Server Control
How Convert a html table control to a Table Web Server Control? add runat="server" attribute to the <table> tag...

HTML Table or Web Control Table?
Hi, I am wondering what is the purpose of using Table web control? It seems to me kind of hard to just drag and drop a textbox or other web controls in the table ... unlike HTML table, we can drag a web controls and just drop it inside the HTML table cell ...? Is there any good tutorial for just how to use the Table control?? There is Microsoft tutorial for table control, is there any others site? I assume you are talking about a data control such as a data grid, data list, or repeater. Try these artciles.... http://aspnet.4guysfromrolla.com/articles/052103-1.aspx http://msdn.micr...

Showing table columns from multiple tables in Formview, but insert/update/delete rows of Master table
I have a page on which I have GridView and FomView control. On selection of a row in GridView the row gets displayed in the Item template of the FormVIew. The values are the result of inner join from multiple tables i.e. table Stock,Product and Workshop.  Please let me know how I could insert/update/delete data for the base table i.e. Stock table, but be able to see the column values from the associated tables on the Itemtemplate,Edittemplate and Inserttemplate of the FormView. Thanks,Anita Hi:   Take a look at this tutorial. It's for DetailsView and same ...

Adding table rows to a table in an update panel
I'm trying to add table rows to a table that has already been added to the update panel (ie, in design view). When I run my code, the text changes on the page, but I dont get additional rows, its as if its forgetting about the first row that was already added and simply over writing it... Anyone got any thoughts?  I had a label in there before where I'd reference the label and add text to the existing text, that worked fine, the text that was already there just stayed and the dialogue got longer etc, why is it different with the table rows? Any help would be appreciated..Rega...

Hiding html table rows and table data
Hello, I have a user control which has an html table with 2 tds per tr like this:<table> <tr> <td style="padding-left:10px;"><asp:HyperLink ID="hlListings" runat="server" ForeColor="#0c6db4"></asp:HyperLink><asp:Label ID="lblAll" runat="server" ForeColor="#999999"></asp:Label></td></tr> <tr> <td style="padding-left:10px;"><asp:HyperLink ID="hlOfferAuction" runat="server" ForeColor="#0c6db4"></asp:Hype...

Adding rows from a table to another table in a dataset
Hi everybody. How can I copy all the data from a dataset's table to another table. The table I'm copying the data to is going to get all the data from that other table several times, cause the source table's data is going to be changing constantly. And I want to store all the data in that table. Is there a function to do that? Or do I have to copy the data row by row? I mean dataset1.tables("table1").rows.add(dataset2.tables("table2").rows(X)) ' where X is the index Thanks in advance newDataTable = dataset1.Tables("table1").CopyMike Ba...

Is having a trigger that inserts a row in Table 'A', when a row in same table is inserted by ADo.Net code?
I want to insert a row for a Global user  in Table 'A' whenever ADO.Net code inserts a Local user row into same table. I recommended using a trigger to implement this functionality, but the DBA was against it, saying that stored proecedures should be used, since triggers are unreliable and slow down the system by placing unecessary locks on the table. Is this true OR the DBA is saying something wrong? My thinking is that Microsoft will never include triggers if they are unreliable and the DBA is just wanting to offload the extra DBA task of triggers to the programmer so that a s...

HTML Table in Table?
Hi All Could I build a HTML table in a HTML table with the outlook of the inner table is one of the cell of the outer table? It is because I found my inner table always smaller than the cell of the TD. What I want to do is the inner table to 100% fill all the td of the outer table? Regards Alex  Hi hnchanyou can easily do it. Pardon for my suggestion, but if you want to do it dynamically then you can use HTMLTable, HTMLTableRow, HTMLTableCell classes to build your table at run time. and easily add cell to your row by simply row.Add method and same for adding table to row.hope...

adding rows in Tables control.
Hi, I have a Table control in asp.net now that table has 5 rows and 4 columns and all columns has a textbox.there is a button "Add".I want that when I click on "Add" button in that table one row and 4 columns will be added in that tableI have done but it create only once, but I want suppose that I click on buttons 4 times then there should be 4 more rows to be add.How can I do it???????????? Dynamically you generate the table. Keep some initial value which will be shown for the first time loading for the no of row. Like suppose 4 the the intial page load time you can a...

Web resources about - adding html table columns from SQL table rows - asp.net.presentation-controls

Politics, Political News - The Capitol Column
Covering the politics of science, technology, business, entertainment, Capitol Hill, and health.

Column vector - Wikipedia, the free encyclopedia
... unclear because it lacks inline citations . Please improve this article by introducing more precise citations. In linear algebra , a column ...

Column 8
Column 8 came across a business card in our wallet this morning, with no clue as to how it got there (we all have cards like that, found days, ...

Paris attacks: column in IS magazine warns of 9/11-scale attack to come
Under the byline of a hostage British journalist, Islamic State warns that it may attempt a terrorist attack even bigger than 9/11.

Becoming The Perfect Faculty Member: An Advice Column
What is tenure all about? Selfish preservation of yourself without regard to the institution, of course.

An NYT ‘Weddings’ Column for the Ages
About the only thing missing from Jamie Diamond ’s epic backgrounder on the Dec. 5 Los Angeles wedding of comedienne Carol Leifer and real estate ...

Patt Rall Column: A little 'Therapy' goes a long way
Patt Rall Column: A little 'Therapy' goes a long way Bemidji Pioneer The entire ensemble is small but intense in their artistic pursuits: Norwood ...

In the middle of a NYT column explaining research into human psychology: "It had no effect on people ...
... in the Middle East among people who identified as politically conservative. It had no effect on people who identified as liberal. The column ...

Sunita Narain: Expectations from Paris - Business Standard Column Widgets Magazine Widgets Magazine Widgets ...
The Paris agreement must accept that all countries have the right to development and that this requires equitable sharing of the global carbon ...

Tim O'Sullivan column:
Concord Monitor Tim O' Sullivan column: Concord Monitor Danny Ainge needs to acquire more talent. Young players like Smart and Olynyk need ...

Resources last updated: 12/17/2015 11:54:03 PM