How can i pass GridView value to google as a hyperlink using asp.net
below is my code
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="SearchEngine.aspx.vb" Inherits="OPAC.SearchEngine" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<meta name="viewport" content="width = device-width, initial-scale = 1.0, minimum-scale = 1.0, maximum-scale = 1.0, user-scalable = no" />
<style type="text/css">
.auto-style1 {
width: 100%;
border: 1px solid #00ffff;
background-color: #008080;
}
.auto-style2 {
background-color: #FFFFFF;
}
</style>
<script type="text/javascript" src="../Scripts/Jquery-3.5.1.js"></script>
<script type="text/javascript" src="../Scripts/Jquery.datatables.min.js"></script>
<script type="text/javascript" src="../Scripts/datatable.fixedColumns.min.js"></script>
<link href="../Scripts/Jquery.datatables.min.css" rel="stylesheet" type="text/css" />
<link href="../Scripts/fixedColumns.dataTables.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
$('#SearchGrid tfoot tr').appendTo('#SearchGrid thead');
$('#SearchGrid').removeAttr('width').DataTable({
bLengthChange: true,
lengthMenu: [[10, 15, -1], [10, 15, "All"]],
bFilter: true,
bSort: true,
scrollCollapse: true,
paging: true,
fixedColumns: false,
orderCellsTop: true
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr>
<td> </td>
<td>
<asp:Button ID="Button1" runat="server" Text="Back To Menu" />
</td>
</tr>
<tr>
<td class="auto-style2" colspan="2">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:GridView ID="SearchGrid" runat="server" CssClass="footable" AutoGenerateColumns="False" Width="1131px">
<Columns>
<asp:BoundField DataField="Bookcode" HeaderText="CallNo" />
<asp:BoundField DataField="BookName" HeaderText="Book Name" />
<asp:BoundField DataField="Author" HeaderText="Author" />
<asp:BoundField DataField="Class" HeaderText="Editions" />
<asp:BoundField DataField="Publisher" HeaderText="Publisher" />
<asp:BoundField HeaderText="Current-InStock" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="false" CommandArgument='<%# Eval("autofield") %>' OnClick="ViewCover" Text="BookCover"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandArgument='<%# Eval("autofield") %>' OnClick="View" Text="PdfView"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="false" CommandArgument='<%# Eval("autofield") %>' OnClick="Viewsummary" Text="SummaryView"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-footable/0.1.0/css/footable.min.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-footable/0.1.0/js/footable.min.js"></script>
<script type="text/javascript">
$(function () {
$('#SearchGrid').footable();
});
</script>
<br />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="SearchGrid" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web.UI.WebControls
Imports System.Web.UI
Imports System.Web
Imports System.Linq
Imports System.Collections.Generic
Imports System
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Word
Public Class SearchEngine
Inherits System.Web.UI.Page
Dim constr As String = ConfigurationManager.ConnectionStrings("SLISConnectionString").ConnectionString
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
BindGrid()
' Logaccount.Text = Session("account").ToString
' LogName.Text = Session("Name").ToString
End If
End Sub
Private Sub BindGrid()
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand()
cmd.CommandText = "SELECT * FROM Stockkabojja"
cmd.Connection = con
con.Open()
SearchGrid.DataSource = cmd.ExecuteReader()
SearchGrid.DataBind()
If SearchGrid.Rows.Count > 0 Then
SearchGrid.UseAccessibleHeader = True
SearchGrid.FooterRow.TableSection = TableRowSection.TableFooter
SearchGrid.HeaderRow.Cells(0).Attributes("data-class") = "expand"
'Attribute to hide column in Phone.
SearchGrid.HeaderRow.Cells(2).Attributes("data-hide") = "phone"
SearchGrid.HeaderRow.Cells(3).Attributes("data-hide") = "phone"
'Adds THEAD and TBODY to GridView.
SearchGrid.HeaderRow.TableSection = TableRowSection.TableHeader
con.Close()
Else
SearchGrid.DataBind()
End If
End Using
End Using
End Sub
Protected Sub View(sender As Object, e As EventArgs)
Dim id As Integer = Integer.Parse(TryCast(sender, LinkButton).CommandArgument)
Try
ProcessRequest2(id, HttpContext.Current)
Catch ex As SystemException
End Try
BindGrid()
End Sub
Protected Sub Viewsummary(sender As Object, e As EventArgs)
Dim id As Integer = Integer.Parse(TryCast(sender, LinkButton).CommandArgument)
Try
ProcessRequest3(id, HttpContext.Current)
Catch ex As SystemException
End Try
BindGrid()
End Sub
Protected Sub ViewCover(sender As Object, e As EventArgs)
Dim id As Integer = Integer.Parse(TryCast(sender, LinkButton).CommandArgument)
Try
ProcessRequest4(id, HttpContext.Current)
Catch ex As SystemException
End Try
BindGrid()
End Sub
Public Sub ProcessRequest2(id As Integer, context As HttpContext)
Dim bytes As Byte()
Dim fileextension As String
Dim constr As String = ConfigurationManager.ConnectionStrings("SLISConnectionString").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand()
cmd.CommandType = CommandType.Text
cmd.Connection = con
con.Open()
cmd.Parameters.AddWithValue("@FileID", id)
cmd.CommandText = "SELECT PDFName, DataPDF FROM stockkabojja WHERE autofield=@FileID"
Using sdr2 As SqlDataReader = cmd.ExecuteReader()
sdr2.Read()
bytes = DirectCast(sdr2("DataPDF"), Byte())
fileextension = sdr2("PDFName").ToString()
End Using
con.Close()
End Using
End Using
context.Response.Buffer = True
context.Response.Charset = ""
context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
If fileextension.Substring(fileextension.IndexOf("."c) + 1).ToLower() = "pdf" Then
context.Response.Buffer = True
context.Response.Charset = ""
context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
context.Response.ContentType = "application/pdf"
context.Response.BinaryWrite(bytes)
context.Response.Flush()
context.Response.[End]()
ElseIf fileextension.Substring(fileextension.IndexOf("."c) + 1).ToLower() = "doc" OrElse fileextension.Substring(fileextension.IndexOf("."c) + 1).ToLower() = "docx" Then
File.WriteAllBytes(Server.MapPath(Convert.ToString("~/Temp/") & fileextension), bytes)
WriteWordFile(Server.MapPath(Convert.ToString("~/Temp/") & fileextension))
End If
End Sub
Public Sub ProcessRequest3(id As Integer, context As HttpContext)
Dim bytes As Byte()
Dim fileextension As String
Dim constr As String = ConfigurationManager.ConnectionStrings("SLISConnectionString").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand()
cmd.CommandType = CommandType.Text
cmd.Connection = con
con.Open()
cmd.Parameters.AddWithValue("@FileID", id)
cmd.CommandText = "SELECT SumName, DataSum FROM stockkabojja WHERE autofield=@FileID"
Using sdr2 As SqlDataReader = cmd.ExecuteReader()
sdr2.Read()
bytes = DirectCast(sdr2("DataSum"), Byte())
fileextension = sdr2("SumName").ToString()
End Using
con.Close()
End Using
End Using
context.Response.Buffer = True
context.Response.Charset = ""
context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
If fileextension.Substring(fileextension.IndexOf("."c) + 1).ToLower() = "pdf" Then
context.Response.Buffer = True
context.Response.Charset = ""
context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
context.Response.ContentType = "application/pdf"
context.Response.BinaryWrite(bytes)
context.Response.Flush()
context.Response.[End]()
Dim constring As String = ConfigurationManager.ConnectionStrings("SLISConnectionString").ConnectionString
Using con As SqlConnection = New SqlConnection(constring)
Using cmd As SqlCommand = New SqlCommand("FileDownloads_UpdateFileDownloadCount", con)
cmd.Parameters.AddWithValue("@FileName", Path.GetFileName(fileextension))
cmd.CommandType = CommandType.StoredProcedure
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
ElseIf fileextension.Substring(fileextension.IndexOf("."c) + 1).ToLower() = "doc" OrElse fileextension.Substring(fileextension.IndexOf("."c) + 1).ToLower() = "docx" Then
File.WriteAllBytes(Server.MapPath(Convert.ToString("~/Temp/") & fileextension), bytes)
WriteWordFile(Server.MapPath(Convert.ToString("~/Temp/") & fileextension))
End If
End Sub
Public Sub ProcessRequest4(id As Integer, context As HttpContext)
Dim bytes As Byte()
Dim fileextension As String
Dim constr As String = ConfigurationManager.ConnectionStrings("SLISConnectionString").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand()
cmd.CommandType = CommandType.Text
cmd.Connection = con
con.Open()
cmd.Parameters.AddWithValue("@FileID", id)
cmd.CommandText = "SELECT CoverName, DataCover FROM stockkabojja WHERE autofield=@FileID"
Using sdr2 As SqlDataReader = cmd.ExecuteReader()
sdr2.Read()
bytes = DirectCast(sdr2("DataCover"), Byte())
fileextension = sdr2("CoverName").ToString()
End Using
con.Close()
End Using
End Using
context.Response.Buffer = True
context.Response.Charset = ""
context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
If fileextension.Substring(fileextension.IndexOf("."c) + 1).ToLower() = "jpg" Then
context.Response.Buffer = True
context.Response.Charset = ""
context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
context.Response.ContentType = "image/jpg"
context.Response.BinaryWrite(bytes)
context.Response.Flush()
context.Response.[End]()
Else
If fileextension.Substring(fileextension.IndexOf("."c) + 1).ToLower() = "png" Then
context.Response.Buffer = True
context.Response.Charset = ""
context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
context.Response.ContentType = "image/png"
context.Response.BinaryWrite(bytes)
context.Response.Flush()
context.Response.[End]()
Else
If fileextension.Substring(fileextension.IndexOf("."c) + 1).ToLower() = "doc" OrElse fileextension.Substring(fileextension.IndexOf("."c) + 1).ToLower() = "docx" Then
File.WriteAllBytes(Server.MapPath(Convert.ToString("~/Temp/") & fileextension), bytes)
WriteWordFile(Server.MapPath(Convert.ToString("~/Temp/") & fileextension))
End If
End If
End If
End Sub
Private Sub WriteWordFile(filePath As Object)
Dim missingType As Object = Type.Missing
Dim [readOnly] As Object = True
Dim isVisible As Object = False
Dim documentFormat As Object = 8
Dim randomName As String = DateTime.Now.Ticks.ToString()
Dim htmlFilePath As Object = (Server.MapPath("~/Temp/") & randomName) + ".htm"
Dim directoryPath As String = (Server.MapPath("~/Temp/") & randomName) + "_files"
Dim applicationclass As New Application
applicationclass.Documents.Open(filePath, [readOnly], missingType, missingType, missingType, missingType,
missingType, missingType, missingType, missingType, isVisible, missingType,
missingType, missingType, missingType, missingType)
applicationclass.Visible = False
Dim document As Document = applicationclass.ActiveDocument
document.SaveAs(htmlFilePath, documentFormat, missingType, missingType, missingType, missingType,
missingType, missingType, missingType, missingType, missingType, missingType,
missingType, missingType, missingType, missingType)
document.Close(missingType, missingType, missingType)
Dim bytes As Byte()
Using fs As New FileStream(htmlFilePath.ToString(), FileMode.Open, FileAccess.Read)
Dim reader As New BinaryReader(fs)
bytes = reader.ReadBytes(CInt(fs.Length))
fs.Close()
End Using
Response.BinaryWrite(bytes)
Response.Flush()
File.Delete(htmlFilePath.ToString())
For Each file_1 As String In Directory.GetFiles(directoryPath)
File.Delete(file_1)
Next
Directory.Delete(directoryPath)
If File.Exists(filePath.ToString()) Then
File.Delete(filePath.ToString())
End If
Response.[End]()
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Response.Redirect("~/Forms/Studentwork.aspx")
End Sub
End Class