- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 HTML 表格而不是 gridview 来获取数据。为什么选择 HTML 表格?因为我将使用电子邮件发送的输出,所以我更喜欢 HTML Table 而不是 gridview。我也不想使用对象,因为系统将只在服务器上运行。它会自动发送一封电子邮件。谁能帮我解决我的问题?谢谢。
这是我目前所拥有的。在下面的示例中,我使用的是 gridview,因为我不知道如何使用 HTML Table 和 Append 来做到这一点。
Vb.Net
这就是我调用函数的方式
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
SendEmail()
End Sub
这是我的电子邮件功能,我想使用追加将其转换为 html 表格。
Protects Sub SendEmail()
For Each dt As System.Data.DataTable In prod3()
Dim i As Integer = i + 1
Dim dv As New System.Data.DataView(dt)
Dim dt2 As System.Data.DataTable = dv.ToTable(False, {"Name", "Product", "Expiry"})
Dim y As Date = dt.Rows(0)("pdate")
Dim dte1, dte2, dte3 As String
Select Case i
Case 1
dte1 = dt.Rows(0)("pdate").ToString
dte1 = y.Date.ToString("MM/dd/yyyy")
dte1 = y
GridView11.DataSource = dt2
GridView11.DataBind()
Case 2
dte2 = dt.Rows(0)("pdate").ToString
dte2 = y.Date.ToString("MM/dd/yyyy")
dte2 = y
GridView12.DataSource = dt2
GridView12.DataBind()
Case 3
dte2 = dt.Rows(0)("pdate").ToString
dte2 = y.Date.ToString("MM/dd/yyyy")
dte2 = y
GridView13.DataSource = dt2
GridView13.DataBind()
End Select
Next
End SUb
Public Function prod3() As List(Of DataTable)
Dim ds As New DataSet
Dim cmd As New SqlCommand
Dim ldt As New List(Of DataTable)
Dim adp As SqlDataAdapter = New SqlDataAdapter
Dim c As New SqlConnection("myconnection")
cmd.Connection = c
cmd.CommandText = "storedprocname"
cmd.Parameters.AddWithValue("@name", "%")
cmd.Parameters.AddWithValue("@product", "%")
cmd.Parameters.AddWithValue("@expiry", "%")
cmd.Parameters.AddWithValue("@datefrom", DateTime.Today.AddDays(1))
cmd.Parameters.AddWithValue("@dateto", DateTime.Today.AddDays(3))
cmd.Parameters.AddWithValue("@cost", "%")
cmd.CommandType = CommandType.StoredProcedure
adp.SelectCommand = cmd
adp.Fill(ds)
Dim dv As New DataView(ds.Tables(0))
Dim dvfilter As DataTable = dv.ToTable(True, {"pdate"})
For Each dtrow As DataRow In dvfilter.Rows
Dim dt2 As New DataTable
dv.RowFilter = "date =#" + dtrow("pdate") + "#"
dt2 = dv.ToTable(False, {"DATE", "Name", "Product", "Expiry"})
ldt.Add(dt2)
Next
Return ldt
End Function
代码可以正常工作,但不是我想要的方式。我不想使用 GridView 。我希望它像这样在 html 表中:
Dim builder As New StringBuilder
builder.Append("<!DOCTYPE html><html>")
builder.Append("<head>")
builder.Append("</head>")
builder.Append("<body>")
builder.Append("<table>")
builder.Append("</table>")
builder.Append("<body>")
任何帮助将不胜感激! :)谢谢。
最佳答案
作为一个选项,您可以使用 Run-Time Text Template创建电子邮件模板。这样您就可以简单地使用模型来使用模板生成输出。这就像使用 ASP.NET MVC 和 Razor 引擎可以做的一样,但它不限于 MVC 甚至 ASP.NET。您可以在任何需要创建模板的地方使用这个想法。
运行时文本模板的工作方式类似于 aspx 页面。对于了解 ASP.NET 的人来说,使用 t4 模板真的很容易。它使用指令和标签,您可以混合内容和代码。您使用代码使输出动态化。然后,当您调用其 TransformText
方法时,它会呈现内容。
您可以使用任何类型作为模型
。该模型可以是您的业务或 View 模型类之一,也可以是 DataTable
。
示例
向您的项目添加一个新类:
Public Class Product
Public Property Name As String
Public Property Price As Integer
End Class
添加一个新的运行时文本模板(也称为预处理模板)并将其命名为 MailTemplate。然后把这个内容放到文件中:
<#@ template language="VB" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ parameter type="System.Collections.Generic.List(Of Product)" name="Model"#>
<html>
<head>
<title>Products</title>
<style type="text/css">
body { font-family: Calibri;width:400px;}
table { text-align:center; }
.container {width:400px;}
</style>
</head>
<body>
<div class="container">
<h1 style="text-align:center;">List of Recent Products</h1><hr/>
Here is list of recent products:
<table style="width:100%">
<tr><th>Index</th><th>Name</th><th>Price</th></tr>
<# Dim index As Integer = 1
For Each item in Model
#>
<tr>
<td><#=index#></td>
<td><#=item.Name#></td>
<td><#=item.Price#></td>
</tr>
<# index = index + 1
Next
#>
</table>
<div>
</body>
</html>
使用此代码在运行时生成输出:
Dim template As New My.Templates.MailTemplate
template.Session = New Dictionary(Of String, Object)
Dim model = New List(Of Product)()
model.Add(New Product With {.Name = "Product 1", .Price = 100})
model.Add(New Product With {.Name = "Product 2", .Price = 100})
model.Add(New Product With {.Name = "Product 3", .Price = 100})
template.Session("Model") = model
template.Initialize()
Dim output = template.TransformText()
现在您可以使用输出来发送电子邮件或将其写入回复。
结果是:
关于html - 使用 HTML Table 而不是 Gridview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39760288/
这个问题在这里已经有了答案: What is the best way to parse html in C#? [closed] (15 个答案) 关闭 3 年前。 string input =
为什么 wrapper #4 没有继承其父表容器的高度?表格嵌套在一个显示 block 包装器中,每个嵌套的div是显示表格,每个表格继承到最里面的一个。是什么原因造成的,我该如何解决? jsfidd
我正在使用带有 Bootstrap 的自定义 css 作为外边框。但顶部边框不可见,除非我将其大小设置为 2 px。 我该如何解决这个问题? HTML #name 1.one 2.two 3.thr
我正在逻辑层面上设计一个数据库,以便稍后将其传递给程序员来交付。我只是粗略地了解它们的工作原理,所以我很难简洁地表达我的问题。这是我的问题: 我有一个名为 MEANINGS 的表。 我有一个名为 WO
在 Laravel 上,我们可以使用 DB::table('table')->get(); 或使用 model::('table')->all() 进行访问;我的问题是它们之间有什么区别? 谢谢。 最
我试图从以下内容中抓取 URL从 WorldOMeter 获取 CoVid 数据,在此页面上存在一个表,id 为:main_table_countries_today其中包含我希望收集的 15x225
这是我的图表数据库:/image/CGAwh.png 我用 SEQUELIZE 制作了我的数据库模型: 型号:级别 module.exports = (sequelize, DataTypes) =>
我真的不明白为什么我的代码不能按预期工作。当我将鼠标悬停在表格的每一行上时,我想显示一个图像(来 self 之前加载的 JSON)。每个图像根据行的不同而不同,我想将它们显示在表格之外的另一个元素中。
假设我的数据库中有一张地铁 map ,其中每条线路的每个站点都是一行。如果我想知道我的线路在哪里互连: mysql> SELECT LineA.stop_id FROM LineA, LineB WH
我最近经常使用这些属性,尤其是 display: table-cell。它在现代浏览器中得到了很好的支持,并且它对某些网格有很多好处,并且可以非常轻松地对齐内容,而无需棘手的标记。但在过去的几天里,我
在 CSS 中,我可以这样做: http://s1.ipicture.ru/uploads/20120612/Uk1Z8iZ1.png http://s1.ipicture.ru/uploads/20
问题作为标题,我正在学习sparkSQL,但我无法很好地理解它们之间的区别。谢谢。 最佳答案 spark.table之间没有区别& spark.read.table功能。 内部 spark.read.
我正在尝试根据 this answer 删除表上的非空约束.但是,它似乎没有在 sqlite_sequence 中创建条目。这样做之后,即使我可以在使用测试表时让它正常工作。 有趣的是,如果我备份我的
var otable = new sap.m.Table();//here table is created //here multiple header I'm trying to create t
下面两种方法有什么区别: 内存 性能 答: select table.id from table B: select a.id from table a 谢谢(抱歉,如果我的问题重复)。 最佳答案 完
我尝试在表格后添加点,方法是使用 table::after 选择器创建一个点元素并使用 margin: 5px auto 5px auto; 将其居中。它有效,但似乎在第一个表格列之后添加了点,而不是
我正在设计一个可以标记任何内容的数据库,我可能希望能够选择带有特定标记的所有内容。 我正在为以下两个选项而苦苦挣扎,希望得到一些建议。如果有更好的方法请告诉我。 选项A 多个“多对多”连接表。 tag
"center" div 中的下表元素导致 "left" div 中的内容从顶部偏移几个像素(在我的浏览器中为 8 ).在表格之前添加一些文本可消除此偏移量。 为什么?如何在不要求在我的表格前添加“虚
我是一名优秀的程序员,十分优秀!