Script(s)

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)
    SendEmail(getHTML(datagrid1))
End Sub

——-

Private Function getHTML(ByVal dataGrid1)Dim result As String

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

htmlWriter.RenderBeginTag(HtmlTextWriterTag.Html)htmlWriter.RenderBeginTag(HtmlTextWriterTag.Body)

DataGrid1.RenderControl(htmlWriter)

htmlWriter.RenderEndTag()

htmlWriter.RenderEndTag()

htmlWriter.Flush()

result = stringWriter.ToString()

Catch ex As Exception‘Error handlersFinally

htmlwriter.Close()stringWriter.Close()

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”)
Try
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.Send(TheMailMessage)

TheMailConnection = Nothing

TheMailMessage = NothingReturn Nothing

Catch ex As Exception
Return Nothing
End Try
End Function

Advertisement

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Connecting to %s

%d bloggers like this: