Code Snippet posted by:
Sagarp | Posted on: 1/25/2010 | Category:
ASP.NET Codes | Views: 1266 | Status:
[Member]
|
Alert Moderator
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Data.SqlClient
Imports System.Threading
Imports System.IO
Imports System.Reflection
Partial Class Customerpurches
Inherits System.Web.UI.Page
Public conmgr As New connectionmanager
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim Sql1 As String
Sql1 = " SELECT Product, SubProduct, Price, CASE qty WHEN 0 THEN 'No' ELSE 'Yes' END Qty FROM Productinfo"
If IsPostBack = False Then
Dim ds2 As DataSet = conmgr.selectdata(Sql1)
GridView2.DataSource = ds2.Tables("temp")
GridView2.DataBind()
'grid()
End If
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Button1.Visible = True
Dim dt As New DataTable()
dt.Columns.Add("Product")
dt.Columns.Add("SubProduct")
dt.Columns.Add("price")
For Each row As GridViewRow In GridView2.Rows
Dim chk As CheckBox = DirectCast(row.FindControl("CheckBox1"), CheckBox)
If chk.Checked = True Then
Dim i As Integer = row.RowIndex
Dim lbl As Label = DirectCast(GridView2.Rows(i).FindControl("lblProduct"), Label)
Dim lbl1 As Label = DirectCast(GridView2.Rows(i).FindControl("lblsubProduct"), Label)
Dim lbl2 As Label = DirectCast(GridView2.Rows(i).FindControl("lblprice"), Label)
Dim dr As DataRow = dt.NewRow()
dr("Product") = Convert.ToString(lbl.Text)
dr("SubProduct") = Convert.ToString(lbl1.Text)
dr("price") = Convert.ToString(lbl2.Text)
dt.Rows.Add(dr)
End If
Next
Session("me") = dt
Dim dg As New GridView
dg.DataSource = dt
dg.DataBind()
Response.Buffer = True
Response.ContentType = "application/ms-excel"
Response.AddHeader("content-disposition", String.Format("attachment;filename={0}.xls", "selectedrows"))
Response.Charset = ""
Dim stringwriter As System.IO.StringWriter = New StringWriter()
Dim htmlwriter As New HtmlTextWriter(stringwriter)
dg.RenderControl(htmlwriter)
Response.Write(stringwriter.ToString())
Response.End()
End Sub
End Sub
End Class
Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/
Found interesting? Add this to: