Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Text
Imports System.Configuration
Public Class depcount
Inherits System.Web.UI.Page
Dim cmd As New SqlCommand
Dim constr As String = System.Configuration.
ConfigurationManager.ConnectionStrings("necserverConnectionString").ConnectionString
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
GridView1.Visible = True
GridView2.Visible = True
If Not IsPostBack Then
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("select dept as Department,count(*) Male_Count from per_det where gen='male' and regno1 in(select distinct regno17 from proof ) group by dept")
Dim dacust1 As New SqlDataAdapter
cmd.Connection = con
dacust1.SelectCommand = cmd
Using dt As New DataTable
dacust1.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
End Using
End Using
End Using
End If
If Not IsPostBack Then
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("select dept AS Department,count(*) Female_Count from per_det where gen='female' and regno1 in(select distinct regno17 from proof ) group by dept")
Dim dacust1 As New SqlDataAdapter
cmd.Connection = con
dacust1.SelectCommand = cmd
Using dt As New DataTable
dacust1.Fill(dt)
GridView2.DataSource = dt
GridView2.DataBind()
End Using
End Using
End Using
End If
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Response.ClearContent()
Response.Buffer = True
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls")
Response.Charset = ""
Response.ContentType = "application/vnd.ms-excel"
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
'If GridView1.Rows.Count <> 0 Then
PrepareForExport(GridView1)
'End If
'If GridView2.Rows.Count <> 0 Then
PrepareForExport(GridView2)
'End If
Dim tb As New Table()
Dim tr1 As New TableRow()
Dim cell1 As New TableCell()
cell1.Controls.Add(GridView1)
tr1.Cells.Add(cell1)
Dim cell3 As New TableCell()
cell3.Controls.Add(GridView2)
Dim cell2 As New TableCell()
cell2.Text = " "
If rbPreference.SelectedValue = "2" Then
tr1.Cells.Add(cell2)
tr1.Cells.Add(cell3)
tb.Rows.Add(tr1)
Else
Dim tr2 As New TableRow()
tr2.Cells.Add(cell2)
Dim tr3 As New TableRow()
tr3.Cells.Add(cell3)
tb.Rows.Add(tr1)
tb.Rows.Add(tr2)
tb.Rows.Add(tr3)
End If
tb.RenderControl(hw)
'style to format numbers to string
Dim style As String = "<style> .textmode { mso-number-format:\@; } </style>"
Response.Write(style)
Response.Output.Write(sw.ToString())
Response.Flush()
Response.[End]()
End Sub
Protected Sub PrepareForExport(ByVal Gridview As GridView)
Gridview.AllowPaging = Convert.ToBoolean(rbPaging.SelectedItem.Value)
Gridview.DataBind()
'Change the Header Row back to white color
Gridview.HeaderRow.Style.Add("background-color", "#FFFFFF")
'Apply style to Individual Cells
For k As Integer = 0 To Gridview.HeaderRow.Cells.Count - 1
Gridview.HeaderRow.Cells(k).Style.Add("background-color", "green")
Next
For i As Integer = 0 To Gridview.Rows.Count - 1
Dim row As GridViewRow = Gridview.Rows(i)
'Change Color back to white
row.BackColor = System.Drawing.Color.White
'Apply text style to each Row
row.Attributes.Add("class", "textmode")
'Apply style to Individual Cells of Alternating Row
If i Mod 2 <> 0 Then
For j As Integer = 0 To Gridview.Rows(i).Cells.Count - 1
row.Cells(j).Style.Add("background-color", "#C2D69B")
Next
End If
Next
End Sub
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
'verifies that the control is rendered
End Sub
End Class