Salut,
First of all, greetings from Romania
I have a project in vb with a gridview in a multiview and i want to save in a workbook excel the gridview displayed data. I have read many articles but in the end i have downloaded the code from http://www.aspsnippets.com/Articles/Export-GridView-To-Word-Excel-PDF-CSV-Formats-in-ASP.Net.aspx and i adapted for my code. The problem is that when i press the ExporttoExcel button it's exporting only this...I cannot figure out that is the problem.
<style> .textmode { mso-number-format:\@; } </style><div>
</div>
Thank you for listening
My code is down
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI.WebControls.TableRow
Imports System.Web.UI.WebControls.GridViewRow
Imports System.Diagnostics
Imports System.IO
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 iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.html
Imports iTextSharp.text.html.simpleparser
Partial Class EvEchipamenteClass
Inherits System.Web.UI.Page
Dim sConn As String = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
Dim oConn As SqlConnection = New SqlConnection(sConn)
Dim login_user As String
Dim _test_grupuri As String = ""
Protected Sub Conn_OPEN()
Try
oConn.Open()
Catch ex As Exception
Response.Write("#01: Nu se poate accesa baza de date !" & ex.Message)
Response.End()
End Try
End Sub
Protected Sub Conn_CLOSE()
Try
oConn.Close()
Catch ex As Exception
Response.Write("#02: Nu se poate accesa baza de date !")
Response.End()
End Try
End Sub
Protected Function Conn_EXEC_SQL(ByVal cmd As String) As SqlDataReader
Dim ooComm As SqlCommand
Dim ooReader As SqlDataReader = Nothing
ooComm = New SqlCommand(cmd, oConn)
Try
ooReader = ooComm.ExecuteReader()
Catch ex As Exception
Response.Write("#03: Nu se poate executa scriptul SQL ! " & ex.Message & " = " & cmd)
Response.End()
End Try
Return ooReader
ooReader.Close()
End Function
Protected Sub MBox(ByVal strMessage As String)
Dim strScript As String = "<script language=JavaScript>alert(""" & strMessage & """);</script>"
If (Not ClientScript.IsStartupScriptRegistered("clientScript")) Then
ClientScript.RegisterClientScriptBlock(Me.GetType(), "clientScript", strScript)
End If
End Sub
Function SafeSqlLiteral(ByVal strValue As String, ByVal in_out As Int32) As String
' int_out =1 - pentru scriere in DB
' int_out =2 - pentru citire din DB
If Not IsDBNull(strValue) Then
If in_out = 1 Then
strValue = Replace(strValue, "'", "''")
strValue = Replace(strValue, "--", "")
strValue = Replace(strValue, "[", "[[]")
strValue = Replace(strValue, "%", "[%]")
ElseIf in_out = 2 Then
strValue = Replace(strValue, "''", "'")
strValue = Replace(strValue, "[[]", "[")
strValue = Replace(strValue, "[%]", "%")
End If
Return strValue
Else
Return strValue
End If
End Function
Public Function getGrupuri() As ArrayList
Dim grupuri As New ArrayList()
If Len(_test_grupuri) = 0 Then
For Each grup As System.Security.Principal.IdentityReference In System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups
grupuri.Add(grup.Translate(GetType(System.Security.Principal.NTAccount)).ToString())
Next
Else
grupuri.Add(_test_grupuri)
End If
Return grupuri
End Function
Public Function matchGrup2Grupuri(ByVal grup2Match As String, ByVal grupuriUserCurent As ArrayList) As Boolean
Dim match As Boolean = False
For Each item As String In grupuriUserCurent
If Trim(item.ToString()) = Trim(grup2Match) Then
match = True
End If
Next
Return match
End Function
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim i As Int16
'If LCase(Request.ServerVariables("LOGON_USER")) <> "star\gg_sps_support_tehnic" Then
' Response.Redirect("~\regis.aspx")
If matchGrup2Grupuri("STAR\gg_sps_support_tehnic", getGrupuri()) = True Then
LinkAdauga1.Visible = True
End If
login_user = Request.ServerVariables("LOGON_USER")
If Not Page.IsPostBack Then
Conn_OPEN()
LSortItem1.Text = "denumire"
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,denumire as denumire,serie, tip , responsabil, zona_amo,observatii from InventarEchipamente" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
For i = 0 To GridView1.Rows.Count - 1
GridView1.Rows(i).Cells(0).BackColor = Drawing.Color.Transparent
'Page.Response.Write("UserCount" + Application.Get("usercount").ToString())
Next
Conn_CLOSE()
End If
End Sub
Protected Sub ButSelect(ByVal sender As Object, ByVal e As System.EventArgs)
Dim m_ClientID As String
Dim rb As New RadioButton
rb = CType(sender, RadioButton)
m_ClientID = rb.ClientID
For Each item As GridViewRow In GridView1.Rows
rb = DirectCast((item.FindControl("RBSelect")), RadioButton)
If m_ClientID = rb.ClientID Then
rb.Checked = True
Else
rb.Checked = False
End If
Next
End Sub
Protected Sub RBList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RBList1.SelectedIndexChanged
Conn_OPEN()
If RBList1.SelectedIndex = 0 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 1 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Admini'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 2 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Coordonare' " & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 3 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Depozit Preluare 1'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 4 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Depozit Preluare 2'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 5 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Depozit Tranzit'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 6 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Indexare 2'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 7 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Indexare 5'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 8 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='IT'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 9 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Management'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 10 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Microfilmare'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 11 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Permanenta'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 12 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Pregatire 1'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 13 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Pregatire 2'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 14 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Reconstituire 1'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 15 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Reconstituire 2'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 16 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Registratura'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 17 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Scanare ADF 1'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 18 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Scanare ADF 2'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 19 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Scanare Manual 1'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 20 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Scanare Manual 2'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 21 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='StarHive/RAM'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
ElseIf RBList1.SelectedIndex = 22 Then
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare,a.denumire,serie,tip,responsabil, zona_amo, observatii from InventarEchipamente a join InventarZona b on a.zona_amo=b.denumire " & _
" where zona_amo='Tranzit-Sedinte'" & _
" order by " & LSortItem1.Text)
GridView1.DataBind()
End If
For i = 0 To GridView1.Rows.Count - 1
GridView1.Rows(i).Cells(0).BackColor = Drawing.Color.Transparent
Next
Conn_CLOSE()
End Sub
Protected Sub ButModifica(ByVal sender As Object, ByVal e As System.EventArgs)
Dim i As Int16
Dim ok As Boolean = False
For i = 0 To GridView1.Rows.Count - 1
If DirectCast((GridView1.Rows(i).Cells(0).FindControl("RBSelect")), RadioButton).Checked Then
ok = True
Exit For
End If
Next
If ok Then
Conn_OPEN()
GridView1.DataSource = Conn_EXEC_SQL("select 0 as RBValue,numar_inventar,cod_clasificare, denumire,serie,tip,responsabil,zona_amo,observatii from InventarEchipamente" & _
" where denumire='" & DirectCast((GridView1.Rows(i).Cells(1).FindControl("denumire_MF")), Label).Text & "' and responsabil='" & DirectCast((GridView1.Rows(i).Cells(1).FindControl("Responsabil")), Label).Text & "'and serie='" & DirectCast((GridView1.Rows(i).Cells(1).FindControl("serie")), Label).Text & "'")
GridView1.DataBind()
DirectCast((GridView1.Rows(0).Cells(0).FindControl("RBSelect")), RadioButton).Checked = True
DirectCast((GridView1.FooterRow.Cells(0).FindControl("BModifica")), Button).Visible = False
TextObservatii1.Text = ""
TextPosesor1.Text = "Admini"
DropDownList2.Visible = True
LTitlu1.Visible = False
RBList1.Visible = False
LinkAdauga1.Visible = False
LObservatii1.Visible = True
LPosesor1.Visible = True
TextObservatii1.Visible = True
TextPosesor1.Visible = True
BRevenire1.Visible = True
BAloca1.Visible = True
BDisponibil1.Visible = False
Conn_CLOSE()
Else
MBox("Nu a fost selectata nicio inregistrare !")
End If
End Sub
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
TextPosesor1.Text = DropDownList2.SelectedItem.Text
End Sub
Protected Sub BRevenire_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BRevenire1.Click
LTitlu1.Visible = True
RBList1.Visible = True
LinkAdauga1.Visible = False
LObservatii1.Visible = False
LPosesor1.Visible = False
TextObservatii1.Visible = False
TextPosesor1.Visible = False
BRevenire1.Visible = False
BAloca1.Visible = False
BDisponibil1.Visible = False
DropDownList2.Visible = False
RBList_SelectedIndexChanged(sender, e)
End Sub
Protected Sub BAloca_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BAloca1.Click
Dim oReader As SqlDataReader
TextObservatii1.Text = Trim(TextObservatii1.Text)
TextPosesor1.Text = Trim(TextPosesor1.Text)
If Len(TextObservatii1.Text) > 0 And Len(TextPosesor1.Text) > 0 Then
Conn_OPEN()
oReader = Conn_EXEC_SQL("update InventarEchipamente set observatii='" & SafeSqlLiteral(TextObservatii1.Text, 1) & "'," & _
"zona_amo= '" & SafeSqlLiteral(TextPosesor1.Text, 1) & "'," & _
"responsabil= '" & login_user & "' where denumire='" & _
DirectCast((GridView1.Rows(0).Cells(0).FindControl("denumire_MF")), Label).Text & "' and Responsabil='" & DirectCast((GridView1.Rows(0).Cells(0).FindControl("Responsabil")), Label).Text & "'and serie='" & DirectCast((GridView1.Rows(0).Cells(0).FindControl("serie")), Label).Text & "'")
oReader = Conn_EXEC_SQL("insert into InventarEchipamenteLog select getdate(),'" & login_user & "','observatii','" & _
SafeSqlLiteral(TextObservatii1.Text, 1) & "','" & _
DirectCast((GridView1.Rows(0).Cells(0).FindControl("Denumire_MF")), Label).Text & "','" & _
DirectCast((GridView1.Rows(0).Cells(0).FindControl("Zona_amo")), Label).Text & "','" & _
SafeSqlLiteral(TextPosesor1.Text, 1) & "'")
'oReader = Conn_EXEC_SQL("insert into amo_servere_log select getdate(),'" & login_user & "','Modificare nume_server','" & _
' e.OldValues("nume_server").ToString() & "','" & _
' e.NewValues("nume_server").ToString() & "','" & _
' e.NewValues("nume_server").ToString() & "'")
'oReader = Conn_EXEC_SQL("insert into InventarEchipamenteLog select getdate(),'" & login_user & "','posesor_temporar','" & _
' SafeSqlLiteral(TextPosesor1.Text, 1) & "','" & _
' DirectCast((GridView1.Rows(0).Cells(0).FindControl("nume")), Label).Text & "'")
Conn_CLOSE()
MBox("Echipamentul a fost alocat!")
'MBox("Dispozitivul a fost alocat!")
DropDownList2.Visible = False
BRevenire_Click(sender, e)
Else
MBox("Completati campurile obligatorii !")
End If
End Sub
'Protected Sub BDisponibil_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BDisponibil1.Click
' Dim oReader As SqlDataReader
' Conn_OPEN()
' oReader = Conn_EXEC_SQL("update InventarEchipamente set observatii='disponibil'," & _
' "posesor_temporar='birou' where nume='" & _
' DirectCast((GridView1.Rows(0).Cells(0).FindControl("nume")), Label).Text & "'and Detinator='" & DirectCast((GridView1.Rows(0).Cells(0).FindControl("Detinator")), Label).Text & "'and serie='" & DirectCast((GridView1.Rows(0).Cells(0).FindControl("serie")), Label).Text & "'")
' oReader = Conn_EXEC_SQL("insert into InventarEchipamenteLog select getdate(),'" & login_user & "','observatii','disponibil','" & _
' DirectCast((GridView1.Rows(0).Cells(0).FindControl("nume")), Label).Text & "'")
' oReader = Conn_EXEC_SQL("insert into InventarEchipamenteLog select getdate(),'" & login_user & "','posesor_temporar','birou','" & _
' DirectCast((GridView1.Rows(0).Cells(0).FindControl("nume")), Label).Text & "'")
' 'MBox("Laptopul/Modem-ul/USB-ul a fost marcat ca disponibil!")
' Conn_CLOSE()
' MBox("Dispozitivul a fost marcat ca disponibil!")
' BRevenire_Click(sender, e)
'End Sub
Protected Sub ButSort(ByVal sender As Object, ByVal e As System.EventArgs)
Dim lbut As New LinkButton
If Not BRevenire1.Visible Then
lbut = CType(sender, LinkButton)
If InStr(LSortItem1.Text.ToUpper, " DESC") > 0 And lbut.Text.ToUpper = Replace(LSortItem1.Text.ToUpper, " DESC", "") Then
LSortItem1.Text = Replace(lbut.Text.ToUpper, "POSESOR TEMPORAR", "posesor_temporar").ToUpper
Else
LSortItem1.Text = Replace(lbut.Text.ToUpper, "POSESOR TEMPORAR", "posesor_temporar").ToUpper & " DESC"
End If
RBList_SelectedIndexChanged(sender, e)
End If
End Sub
Protected Sub DropDownList3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList3.SelectedIndexChanged
Textzona_amo2.Text = DropDownList3.SelectedItem.Text
End Sub
Protected Sub LinkAdauga1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkAdauga1.Click
MultiView1.ActiveViewIndex = 1
TextNumarInventar2.Text = ""
TextCodClasificare2.Text = ""
TextDenumire2.Text = ""
TextSerie2.Text = ""
TextTip2.Text = ""
TextResponsabil2.Text = ""
Textzona_amo2.Text = ""
Textobservatii2.Text = ""
End Sub
Protected Sub BRevenire2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BRevenire2.Click
MultiView1.ActiveViewIndex = 0
End Sub
Protected Sub BAdauga2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BAdauga2.Click
Dim oReader As SqlDataReader
If Len(TextDenumire2.Text) > 0 And Len(TextResponsabil2.Text) > 0 And Len(TextTip2.Text) > 0 And _
Len(Textobservatii2.Text) > 0 And Len(TextSerie2.Text) > 0 Then
TextDenumire2.Text = TextDenumire2.Text.ToUpper
'If Not System.Text.RegularExpressions.Regex.IsMatch(TextDenumire2.Text, "") Then
' MBox("LIPSA denumire")
' Exit Sub
'End If
'If Not System.Text.RegularExpressions.Regex.IsMatch(TextResponsabil2.Text, "") Then
' MBox("LIPSA Responsabil")
' Exit Sub
'End If
Conn_OPEN()
oReader = Conn_EXEC_SQL("select denumire from InventarEchipamente where denumire='" & TextDenumire2.Text & "' and responsabil='" & TextResponsabil2.Text & "' and serie='" & TextSerie2.Text & "' ")
If oReader.Read Then
MBox(TextDenumire2.Text & " exista deja in evidente !")
Conn_CLOSE()
Exit Sub
End If
If Len(TextNumarInventar2.Text) > 0 Or Len(TextCodClasificare2.Text) > 0 Then
oReader = Conn_EXEC_SQL("insert into InventarEchipamente select '" & SafeSqlLiteral(TextNumarInventar2.Text, 1) & "','" & SafeSqlLiteral(TextCodClasificare2.Text, 1) & "','" & _
SafeSqlLiteral(TextDenumire2.Text, 1) & "','" & SafeSqlLiteral(TextSerie2.Text, 1) & "','" & SafeSqlLiteral(TextTip2.Text, 1) & _
"','" & SafeSqlLiteral(TextResponsabil2.Text, 1) & _
"','" & SafeSqlLiteral(Textzona_amo2.Text, 1) & _
"','" & SafeSqlLiteral(Textobservatii2.Text, 1) & "'")
'Else
' oReader = Conn_EXEC_SQL("insert into InventarEchipamente select '" & SafeSqlLiteral(TextNumarInventar2.Text, 1) & "','" & SafeSqlLiteral(TextCodClasificare2.Text, 1) & "','" & _
' SafeSqlLiteral(TextDenumire2.Text, 1) & "','" & SafeSqlLiteral(TextSerie2.Text, 1) & "',NULL,'" & SafeSqlLiteral(Textobservatii2.Text, 1) & _
'"','" & SafeSqlLiteral(TextPosesor2.Text, 1) & "'")
End If
'oReader = Conn_EXEC_SQL("insert into InventarEchipamenteLog select getdate(),'" & login_user & "','ADAUGARE Dispozitiv','!!!!!','" & _
' SafeSqlLiteral(TextNume2.Text, 1) & "'")
MBox(TextDenumire2.Text & " a fost adaugat !")
Conn_CLOSE()
TextNumarInventar2.Text = ""
TextCodClasificare2.Text = ""
TextDenumire2.Text = ""
TextSerie2.Text = ""
TextTip2.Text = ""
TextResponsabil2.Text = ""
Textzona_amo2.Text = ""
Textobservatii2.Text = ""
Else
MBox("Toate campurile sunt obligatorii mai putin campul Numar Inventar si Cod Clasificare !")
End If
End Sub
Private Function GetData(ByVal cmd As SqlCommand) As DataTable
Dim dt As New DataTable()
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings("conString").ConnectionString
Dim con As New SqlConnection(strConnString)
Dim sda As New SqlDataAdapter()
cmd.CommandType = CommandType.Text
cmd.Connection = con
Try
con.Open()
sda.SelectCommand = cmd
sda.Fill(dt)
Return dt
Catch ex As Exception
Throw ex
Finally
con.Close()
sda.Dispose()
con.Dispose()
End Try
End Function
Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
' Verifies that the control is rendered
End Sub
Protected Sub OnPaging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
GridView1.PageIndex = e.NewPageIndex
GridView1.DataBind()
End Sub
Protected Sub btnExportWord_Click(ByVal sender As Object, ByVal e As EventArgs)
Response.Clear()
Response.Buffer = True
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.doc")
Response.Charset = ""
Response.ContentType = "application/vnd.ms-word "
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
GridView1.AllowPaging = False
GridView1.DataBind()
GridView1.RenderControl(hw)
Response.Output.Write(sw.ToString())
Response.Flush()
Response.[End]()
End Sub
Protected Sub btnExportExcel_Click(ByVal sender As Object, ByVal e As EventArgs)
Response.Clear()
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)
GridView1.AllowPaging = False
GridView1.DataBind()
'Change the Header Row back to white color
GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF")
'Apply style to Individual Cells
GridView1.HeaderRow.Cells(0).Style.Add("background-color", "green")
GridView1.HeaderRow.Cells(1).Style.Add("background-color", "green")
GridView1.HeaderRow.Cells(2).Style.Add("background-color", "green")
GridView1.HeaderRow.Cells(3).Style.Add("background-color", "green")
GridView1.HeaderRow.Cells(4).Style.Add("background-color", "green")
GridView1.HeaderRow.Cells(5).Style.Add("background-color", "green")
GridView1.HeaderRow.Cells(6).Style.Add("background-color", "green")
GridView1.HeaderRow.Cells(7).Style.Add("background-color", "green")
GridView1.HeaderRow.Cells(8).Style.Add("background-color", "green")
For i As Integer = 0 To GridView1.Rows.Count - 1
Dim row As GridViewRow = GridView1.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
row.Cells(0).Style.Add("background-color", "#C2D69B")
row.Cells(1).Style.Add("background-color", "#C2D69B")
row.Cells(2).Style.Add("background-color", "#C2D69B")
row.Cells(3).Style.Add("background-color", "#C2D69B")
row.Cells(4).Style.Add("background-color", "#C2D69B")
row.Cells(5).Style.Add("background-color", "#C2D69B")
row.Cells(6).Style.Add("background-color", "#C2D69B")
row.Cells(7).Style.Add("background-color", "#C2D69B")
row.Cells(8).Style.Add("background-color", "#C2D69B")
End If
Next
GridView1.RenderControl(hw)
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 btnExportPDF_Click(ByVal sender As Object, ByVal e As EventArgs)
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
GridView1.AllowPaging = False
GridView1.DataBind()
GridView1.RenderControl(hw)
Dim sr As New StringReader(sw.ToString())
Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 0.0F)
Dim htmlparser As New HTMLWorker(pdfDoc)
PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
htmlparser.Parse(sr)
pdfDoc.Close()
Response.Write(pdfDoc)
Response.End()
End Sub
Protected Sub btnExportCSV_Click(ByVal sender As Object, ByVal e As EventArgs)
Response.Clear()
Response.Buffer = True
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.csv")
Response.Charset = ""
Response.ContentType = "application/text "
GridView1.AllowPaging = False
GridView1.DataBind()
Dim sb As New StringBuilder()
For k As Integer = 0 To GridView1.Columns.Count - 1
'add separator
sb.Append(GridView1.Columns(k).HeaderText + ","c)
Next
'append new line
sb.Append(vbCr & vbLf)
For i As Integer = 0 To GridView1.Rows.Count - 1
For k As Integer = 0 To GridView1.Columns.Count - 1
'add separator
sb.Append(GridView1.Rows(i).Cells(k).Text + ","c)
Next
'append new line
sb.Append(vbCr & vbLf)
Next
Response.Output.Write(sb.ToString())
Response.Flush()
Response.End()
End Sub
End Class