what I learn is what u c

Export Datagrid to HTML

leave a comment »

If you want to export the contents of Datagrid and save it as file or send it by email… there is a simpler way ..

Private Sub btnDataGridEmail_Click(object sender, System.EventArgs e)
End Sub


Private Function getHTML(ByVal dataGrid1)Dim result As String

Dim stringwriter As New StringWriterDim htmlwriter As HtmlTextWriterhtmlwriter = New HtmlTextWriter(stringWriter)Try






result = stringWriter.ToString()

Catch ex As Exception‘Error handlersFinally


getHTML = result

End Try

End Function——————- 

Public Function SendEmail(ByVal sMessage As String) As Integer

Dim sFromEmail As StringDim sToEmail As String

Dim sSubject As StringDim sSmtp As String

sFromEmail = ConfigurationSettings.AppSettings(“MailFrom”)
sToEmail = ConfigurationSettings.AppSettings(“MailTo”)
sSubject = “DataGrid Values”
sSmtp = ConfigurationSettings.AppSettings(“MailServer”)
Dim TheMailMessage As New MailMessageDim TheMailConnection As SmtpMailTheMailMessage.From = sFromEmailTheMailMessage.To = sToEmail

‘Request.ServerVariables(“REMOTE_ADDR”) : returns the IP

‘ System.Environment.MachineName : returns the Machine Name (when multiple servers are in load balancing)

TheMailMessage.Subject = sSubject & ” – ” & Request.ServerVariables(“REMOTE_ADDR”) & ” – ” & System.Environment.MachineName

TheMailMessage.Body = sMessage

TheMailMessage.BodyFormat = MailFormat.Html

TheMailConnection.SmtpServer = sSmtp


TheMailConnection = Nothing

TheMailMessage = NothingReturn Nothing

Catch ex As Exception
Return Nothing
End Try
End Function


Written by gchandra

August 23, 2006 at 10:55 am

Posted in Web Coding

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: