Response.write "<table width=""100%"" border=""1"">"
'iRow is used as a table row counter
iRow=0
'If there are records then loop through the fields
for(int i =0; i<2; i++)
'Use Mod operator
If iRow Mod 2 = 0 Then
response.write "<tr bgcolor=""#F7F7F7"">"
Else
response.write "<tr bgcolor=""#CCCCCC"">"
End If
response.write "<td>"
response.write recordset("FirstName") & " " & recordset("SurName")
response.write "</td>"
'Increment iRow counter
iRow=iRow + 1
'move on to the next record
Recordset.MoveNext
Loop
response.write "</tr>"
Response.write "</table>"
PedroRibeiro
Member
94 Points
149 Posts
VB. NET generate a dinamyc table with one line of each color
May 08, 2012 08:55 AM|LINK
Hi,
I am developing an app in vb.net (4.0) .
I would like to generate a dinamic table (with rows in two different colors) based on the result of a query returned by my Entity Framework.
How can I do this?
I only know how to do this using a gridview and then bind the drig wih data.
I don't want to use a gried view, I want to use HTML to generate the same layout as a gridview.
santosh.jagd...
Star
7625 Points
1454 Posts
Re: VB. NET generate a dinamyc table with one line of each color
May 08, 2012 09:23 AM|LINK
Response.write "<table width=""100%"" border=""1"">" 'iRow is used as a table row counter iRow=0 'If there are records then loop through the fields for(int i =0; i<2; i++) 'Use Mod operator If iRow Mod 2 = 0 Then response.write "<tr bgcolor=""#F7F7F7"">" Else response.write "<tr bgcolor=""#CCCCCC"">" End If response.write "<td>" response.write recordset("FirstName") & " " & recordset("SurName") response.write "</td>" 'Increment iRow counter iRow=iRow + 1 'move on to the next record Recordset.MoveNext Loop response.write "</tr>" Response.write "</table>"MCP
tusharrs
Contributor
3230 Points
668 Posts
Re: VB. NET generate a dinamyc table with one line of each color
May 08, 2012 09:33 AM|LINK
Table tbl = new Table(); for (int i =0;i<=10 ;i++) { TableRow tr = new TableRow(); TableCell tc = new TableCell(); tc.Text = "cell " + i.ToString(); if ((i % 2) == 0) { tc.BackColor = System.Drawing.Color.Yellow; } else { tc.BackColor = System.Drawing.Color.Blue ; } tr.Controls.Add(tc); tbl.Controls.Add(tr); } this.Controls.Add(tbl);( Mark as Answer if it helps you out )
View my Blog
PedroRibeiro
Member
94 Points
149 Posts
Re: VB. NET generate a dinamyc table with one line of each color
May 08, 2012 01:46 PM|LINK
Thank you for the feedback.
I want to put that inside a table I already have in html.
My code HTML code is this:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="EmailFacturas.aspx.vb" Inherits="WebRole1.EmailFacturas" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head" runat="server"> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>SGCA - Sistema de Gestão de Competição Automóvel</title> <style type="text/css"> .auto-style2 { text-align: center; margin-top: 0; margin-bottom: 0; width: 1004px; } .auto-style3 { margin-top: 0; margin-bottom: 0; } .auto-style4 { border-width: 0px; } .auto-style5 { outline-color:Black } </style> </head> <body style="background-image: url('styles/fundo%20da%20pagina%20do%20aplicativo.jpg')"> <form id="Form1" runat="server" style="background-color:White; width:1005px; height:731px; margin:auto auto auto auto;"> <div class="page" style="background-position:center; border-top:10px; border-top-color:White" > <p style="border-bottom-color:White; height:6px;"></p> <p class="auto-style2"><img alt="" height="79" src="styles/banner1.jpg" width="967" /><img alt="" height="150" src="styles/banner2.jpg" width="967" /></p> <p class="auto-style2"> <p class="auto-style2"> <img alt="" height="4" src="styles/separador%201.jpg" width="966" /> </p> </div> <div class="main"> <table style="background-color:white; border-color:White; margin:auto auto auto auto; height: 50px; width: 550px;"> <tr> <td> </td> </tr> </table> <table style="background-color:white; border-color:White; margin:auto auto auto auto; height: 50px; width: 550px;"> <tr> <td> <asp:Label ID="Label1" runat="server" Text="Acção:" Width="500px"></asp:Label> </td> </tr> </table> <table style="background-color:White; border-color:White; margin:auto auto auto auto; height: 50px; width: 550px;"> <tr> <td> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </td> <td> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </td> <td> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> </td> </tr> </table> <table style="background-color:White; border-color:White; margin:auto auto auto auto; height: 50px; width: 550px;"> <tr> <td> <asp:TextBox ID="TextBox4" runat="server" Width="512px"></asp:TextBox> </td> </tr> </table> <table style="background-color:White; border-color:White; margin:auto auto auto auto; height: 150px; width: 550px;"> <tr> <td> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> </td> </tr> </table> <table style="background-color:White; border-color:White; margin:auto auto auto auto; height: 50px; width: 550px;"> <tr> <td style="width:180px;"> </td> <td style="width:180px;"> </td> <td> <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox> </td> </tr> </table> </div> <div class="footer"> <p class="auto-style2"><img alt="" height="53" src="styles/rodape.jpg" border="0px" style="width: 967px"/></p> </div> </form> </body> </html>I want to display that table where I have my gridview1 rigth now (I will delete gridview from code).
How to do it?
thank you
tusharrs
Contributor
3230 Points
668 Posts
Re: VB. NET generate a dinamyc table with one line of each color
May 08, 2012 03:22 PM|LINK
.( Mark as Answer if it helps you out )
View my Blog