I want to use HTML table instead of gridview to fecth the data. Why HTML Table? Because I'll be using the output for email sending so I prefer HTML Table instead of gridview. Also I don't want to use object as the system will run on the server only. It will automatically send an email. Can anyone help me with my problem? Thank you.
Here is what I have so far. On the example below I'm using gridview because I don't know how to do it using HTML Table using Append.
Vb.Net
This is how I call my function
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
SendEmail()
End Sub
This is my email function that i want to be converted into html table using append.
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
The code is working but not the way I want. I don't want to use gridview. I want it to be in html table like :
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>")
Any help would be much appreciated! :) Thank you.