﻿Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports QueryString
Imports RewriteModule
Imports System.Web
Imports System.Web.UI
Imports System.Text.RegularExpressions

Partial Class UserControl_ProductDisplay
    Inherits System.Web.UI.UserControl
    Dim cmd As New SqlCommand
    Dim dr As SqlDataReader
    Dim CatSearch As String
    Dim prodid As String
    Dim catid As String
    Dim strr As String
    Shared searchopt As String
    Dim keyval As Integer
    Dim BrandId As String
    Shared prodkey As String
    Shared searchkey As String
    Dim da As SqlDataAdapter
    Shared val1 As String
    Shared val2 As String
    Shared val3 As String
    Shared flag As Boolean
    Dim total As Integer = 0
    Dim dtCategoryDistinct As DataTable
    Dim dt1, dt As DataTable

#Region "Events"
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        imgbtnCompare.ImageUrl = Page.ResolveUrl("~/Images/compare-item.jpg")
        imglbtnAddtoWiseList.ImageUrl = Page.ResolveUrl("~/Images/addto-wishlist.jpg")
        If Not IsPostBack Then
            txtCounter.Attributes.Add("onkeypress", "return blockNonNumbers(this,event,false,false);")
            Dim pageCounter As Integer
            If txtCounter.Text = "" Or txtCounter.Text Is Nothing Then
                pageCounter = 0
            Else
                pageCounter = CType(txtCounter.Text.ToString, Integer) - 1
                Session("pageCounter") = pageCounter
            End If

            If IsNothing(CatDistinct) Then
                GetCatDistinct()
            End If
            dtCategoryDistinct = CatDistinct

            If Request.QueryString("Product_KId") = Nothing Then
            Else
                productinfo(pageCounter)
                fillURL(CType(Session("Product"), DataTable).Rows(0)("Product_CategoryId").ToString)
            End If

            If Request.QueryString("Brand_KId") = Nothing Then
                Session("brandid") = Nothing
            Else
                Session("brandid") = DecodeURL(Request.QueryString("Brand_KId"))
                BrandSelectedInfo(pageCounter)
            End If

            If Request.QueryString("Product_HId") = Nothing Then
            Else
                Session("catid") = DecodeURL(Request.QueryString("Product_HId"))
                CategorySelectedInfoHead(DecodeURL(Request.QueryString("Product_HId")), pageCounter)
                fillURL(DecodeURL(Request.QueryString("Product_HId")))
            End If

            If Request.QueryString("Product_Id") = Nothing Then
            Else
                Session("catid") = DecodeURL(Request.QueryString("Product_Id"))
                CategorySelectedInfo(DecodeURL(Request.QueryString("Product_Id")), pageCounter)
                fillURL(DecodeURL(Request.QueryString("Product_Id")))
            End If

            If Request.QueryString("Product_DId") = Nothing Then
            Else
                CategorySelectedInfo(Request.QueryString("Product_DId"), pageCounter)
                fillURL(Request.QueryString("Product_DId"))
            End If

            If Request.QueryString("key") = Nothing Then
            Else
                search_product(pageCounter)
            End If

            If Label1.Visible = True Then
                lnkInquiry.Attributes.Add("onclick", "return OpenInquery();")
            End If

            lblPageCounter.Text = gvProductDisplay.PageCount.ToString
            If pageCounter = 0 And gvProductDisplay.PageCount = 1 Then
                lbtnBack.Visible = False
                lbtnNext.Visible = False
                txtCounter.Text = "1"
            ElseIf pageCounter = 0 Then
                txtCounter.Text = "1"
            End If
        End If
    End Sub

    Protected Sub gvProductDisplay_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvProductDisplay.PageIndexChanging
        gvProductDisplay.PageIndex = e.NewPageIndex

        Dim pageCounter As Integer
        If txtCounter.Text = "" Or txtCounter.Text Is Nothing Then
            pageCounter = 0
        Else
            pageCounter = CType(txtCounter.Text.ToString, Integer) - 1
        End If

        If Not CatSearch = Nothing Then
            'CategorySelectedInfo()
        End If
        If Not prodid = Nothing Then
            productinfo(pageCounter)
        End If
        If Not BrandId = Nothing Then
            BrandSelectedInfo(pageCounter)
        End If
        If Not searchopt = Nothing Then
            search_product(pageCounter)
        End If
        If Not catid = Nothing Then
            'CategorySelectedInfo()
        End If
    End Sub

    Protected Sub gvProductDisplay_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvProductDisplay.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim lblprice As Label = CType(e.Row.Cells(0).FindControl("lblprice"), Label)
            Dim lnkprice As LinkButton = CType(e.Row.Cells(0).FindControl("lnkprice"), LinkButton)
            Dim ID As String
            ID = lnkprice.CommandArgument.ToString
            CType(e.Row.Cells(0).FindControl("lnkprice"), LinkButton).Attributes.Add("onclick", "return openform('" & EncodeURL(ID) & "');")
            CType(e.Row.Cells(0).FindControl("imgbtn"), Image).Attributes.Add("onmouseover", "ImageAspectRatio(this,'" & Image1.ClientID.ToString & "',400,300);")
            CType(e.Row.Cells(0).FindControl("imgbtn"), Image).Attributes.Add("onmouseout", "enlargimgout(this,'" & Image1.ClientID.ToString & "');")
            lblprice.Text = "Rs. " & Producttotalprice(lnkprice.CommandArgument.ToString)
            If (lblprice.Text.ToString() <> "") Then
                If Convert.ToDouble(lblprice.Text.Replace("Rs. ", "").Trim) = 0 Then
                    lblprice.Visible = False
                    lnkprice.Visible = True
                Else
                    lblprice.Visible = True
                    lnkprice.Visible = False
                End If
            Else
                lblprice.Visible = False
                lnkprice.Visible = True
            End If

            If e.Row.RowState = DataControlRowState.Normal Then
                e.Row.BackColor = Drawing.Color.White
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#d5e7ff'")
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
            End If

            If e.Row.RowState = DataControlRowState.Alternate Then
                Dim c As Drawing.Color
                c = Drawing.Color.FromArgb(226, 226, 226)
                e.Row.BackColor = c
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#d5e7ff'")
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#E6EFF6'")
            End If
        End If

        If e.Row.RowType = DataControlRowType.Footer Then
            Dim nextimg, backimg As String
            nextimg = "Images/aroow_inside.jpg"
            backimg = "Images/raroow_inside.jpg"
            CType(e.Row.Cells(0).FindControl("hrlNext"), HyperLink).Text = "Next <img src='" & Page.ResolveUrl(nextimg) & "' alt='Next' style='height: 10px; width: 21px;border:none;' /> "
            CType(e.Row.Cells(0).FindControl("hrlBack"), HyperLink).Text = "<img src='" & Page.ResolveUrl(backimg) & "' alt='Back' style='height: 10px; width: 21px;border:none;' /> Back"
        End If
    End Sub

    Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim chk1 As New CheckBox
        Dim chk2 As New CheckBox
        Dim i As Integer
        chk1 = CType(sender, CheckBox)
        If chk1.Checked = True Then
            For i = 0 To gvProductDisplay.Rows.Count - 1
                CType(gvProductDisplay.Rows(i).FindControl("CheckBox2"), CheckBox).Checked = True
            Next
        Else
            For i = 0 To gvProductDisplay.Rows.Count - 1
                CType(gvProductDisplay.Rows(i).FindControl("CheckBox2"), CheckBox).Checked = False
            Next
        End If
        gvProductDisplay.Visible = True
        imgbtnCompare.Visible = True
        imglbtnAddtoWiseList.Visible = True
        ItemFound.Visible = True
        Label2.Visible = True
        Label1.Visible = False
    End Sub

    Protected Sub imgbtnCompare_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgbtnCompare.Click
        gvProductDisplay.Visible = True
        imgbtnCompare.Visible = True
        ItemFound.Visible = True
        imglbtnAddtoWiseList.Visible = True
        Dim hashData As New Hashtable
        Dim i As Integer
        Dim j As Integer = 0
        For i = 0 To gvProductDisplay.Rows.Count - 1
            If CType(gvProductDisplay.Rows(i).FindControl("CheckBox2"), CheckBox).Checked = True Then
                hashData.Add("ItemMaxMin" & j, gvProductDisplay.DataKeys(i).Value)
                j += 1
            End If
        Next

        Session("ItemMaxMin") = Nothing
        Session("ItemCount") = Nothing
        Session("ItemMaxMin") = hashData
        Session("ItemCount") = j
        If j < 2 Or j > 3 Then
            ItemMinMax.Visible = True
            ItemMinMax.Text = "<br/><img alt='' src='" & Page.ResolveUrl("~/Images/javascripts.gif") & "' /> Please Select Minimum Two Products/Maximum Three Products."
            Label2.Visible = True
            Exit Sub
        Else
            Session("ProductCode") = Nothing
            ItemMinMax.Text = ""
            ItemMinMax.Visible = False
            Response.Redirect("~/Compare.aspx")
        End If
    End Sub

    Protected Sub imglbtnAddtoWiseList_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imglbtnAddtoWiseList.Click
        Try
            gvProductDisplay.Visible = True
            imgbtnCompare.Visible = True
            ItemFound.Visible = True
            imglbtnAddtoWiseList.Visible = True
            Dim gvRow As GridViewRow
            Dim Wishtabel As New DataTable
            Wishtabel.Columns.Add("ProductId")
            If Session("BuyId") = Nothing Then
                For Each gvRow In gvProductDisplay.Rows
                    If CType(gvRow.FindControl("CheckBox2"), CheckBox).Checked = True Then
                        Dim wsrow As DataRow = Wishtabel.NewRow
                        wsrow("ProductId") = gvProductDisplay.DataKeys(gvRow.RowIndex).Value
                        Wishtabel.Rows.Add(wsrow)
                    End If
                Next

                If Wishtabel.Rows.Count < 1 Then
                    ItemMinMax.Visible = True
                    ItemMinMax.Text = "<br/><img alt='' src='" & Page.ResolveUrl("~/Images/javascripts.gif") & "'/>Please Select Minimum One  Product."
                    Session("WishTabel") = Nothing
                    Exit Sub
                Else
                    Session("WishTabel") = Nothing
                    Session("WishTabel") = Wishtabel
                    Session("Checkstatus") = "WishLsit"
                    ItemMinMax.Text = ""
                    ItemMinMax.Visible = False
                    'Response.Redirect("home.aspx")
                    Response.Redirect("~/Buyer/BuyerLogin.aspx")
                End If
            Else
                For Each gvRow In gvProductDisplay.Rows
                    If CType(gvRow.FindControl("CheckBox2"), CheckBox).Checked = True Then
                        If WishListProcedure("Insert", gvRow) = True Then
                            total = total + 1
                        End If
                    End If
                Next
                Response.Redirect("~/Buyer/WishList.aspx")
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    '------Updated By Prachi - 14/09/2009 - to display pager for gridview------
    Protected Sub txtCounter_Changed(ByVal sender As Object, ByVal e As EventArgs) Handles txtCounter.TextChanged
        Try
            Dim pageCounter As Integer
            If txtCounter.Text = "" Or txtCounter.Text Is Nothing Or txtCounter.Text = "0" Then
                pageCounter = 0
                txtCounter.Text = "1"
            Else
                pageCounter = CType(txtCounter.Text.ToString, Integer) - 1
            End If

            If pageCounter = 0 And gvProductDisplay.PageCount = 1 Then
                lbtnBack.Visible = False
                lbtnNext.Visible = False
            Else
                If pageCounter = 0 Then
                    lbtnBack.Visible = False
                    lbtnNext.Visible = True
                    txtCounter.Text = "1"
                ElseIf pageCounter >= 1 And pageCounter < gvProductDisplay.PageCount - 1 Then
                    lbtnBack.Visible = True
                    lbtnNext.Visible = True
                ElseIf pageCounter = gvProductDisplay.PageCount - 1 Or pageCounter >= gvProductDisplay.PageCount Then
                    lbtnBack.Visible = True
                    lbtnNext.Visible = False
                    txtCounter.Text = gvProductDisplay.PageCount
                End If
            End If

            If IsNothing(CatDistinct) Then
                GetCatDistinct()
            End If
            dtCategoryDistinct = CatDistinct

            If Request.QueryString("Product_KId") = Nothing Then
            Else
                productinfo(pageCounter)
                fillURL(CType(Session("Product"), DataTable).Rows(0)("Product_CategoryId").ToString)
            End If

            If Request.QueryString("Brand_KId") = Nothing Then
                Session("brandid") = Nothing
            Else
                Session("brandid") = DecodeURL(Request.QueryString("Brand_KId"))
                BrandSelectedInfo(pageCounter)
            End If

            If Request.QueryString("Product_HId") = Nothing Then
            Else
                Session("catid") = DecodeURL(Request.QueryString("Product_HId"))
                CategorySelectedInfoHead(DecodeURL(Request.QueryString("Product_HId")), pageCounter)
                fillURL(DecodeURL(Request.QueryString("Product_HId")))
            End If

            If Request.QueryString("Product_Id") = Nothing Then
            Else
                Session("catid") = DecodeURL(Request.QueryString("Product_Id"))
                CategorySelectedInfo(DecodeURL(Request.QueryString("Product_Id")), pageCounter)
                fillURL(DecodeURL(Request.QueryString("Product_Id")))
            End If

            If Request.QueryString("Product_DId") = Nothing Then
            Else
                CategorySelectedInfo(Request.QueryString("Product_DId"), pageCounter)
                fillURL(Request.QueryString("Product_DId"))
            End If

            If Request.QueryString("key") = Nothing Then
            Else
                search_product(pageCounter)
            End If

            If Label1.Visible = True Then
                lnkInquiry.Attributes.Add("onclick", "return OpenInquery();")
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub lbtnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtnNext.Click
        Dim pageCounter As Integer
        If txtCounter.Text = "" Or txtCounter.Text Is Nothing Or txtCounter.Text = "0" Then
            pageCounter = 0
            txtCounter.Text = "1"
        Else
            pageCounter = CType(txtCounter.Text.ToString, Integer) - 1
        End If

        pageCounter = pageCounter + 1
        If pageCounter = gvProductDisplay.PageCount Then
            txtCounter.Text = pageCounter
        Else
            txtCounter.Text = pageCounter + 1
        End If

        If pageCounter = 0 And gvProductDisplay.PageCount = 1 Then
            lbtnBack.Visible = False
            lbtnNext.Visible = False
        Else
            If pageCounter = 0 Then
                lbtnBack.Visible = False
                lbtnNext.Visible = True
                txtCounter.Text = "1"
            ElseIf pageCounter >= 1 And pageCounter < gvProductDisplay.PageCount - 1 Then
                lbtnBack.Visible = True
                lbtnNext.Visible = True
            ElseIf pageCounter = gvProductDisplay.PageCount - 1 Or pageCounter >= gvProductDisplay.PageCount Then
                lbtnBack.Visible = True
                lbtnNext.Visible = False
                txtCounter.Text = gvProductDisplay.PageCount
            End If
        End If

        If IsNothing(CatDistinct) Then
            GetCatDistinct()
        End If
        dtCategoryDistinct = CatDistinct

        If Request.QueryString("Product_KId") = Nothing Then
        Else
            productinfo(pageCounter)
            fillURL(CType(Session("Product"), DataTable).Rows(0)("Product_CategoryId").ToString)
        End If

        If Request.QueryString("Brand_KId") = Nothing Then
            Session("brandid") = Nothing
        Else
            Session("brandid") = DecodeURL(Request.QueryString("Brand_KId"))
            BrandSelectedInfo(pageCounter)
        End If

        If Request.QueryString("Product_HId") = Nothing Then
        Else
            Session("catid") = DecodeURL(Request.QueryString("Product_HId"))
            CategorySelectedInfoHead(DecodeURL(Request.QueryString("Product_HId")), pageCounter)
            fillURL(DecodeURL(Request.QueryString("Product_HId")))
        End If

        If Request.QueryString("Product_Id") = Nothing Then
        Else
            Session("catid") = DecodeURL(Request.QueryString("Product_Id"))
            CategorySelectedInfo(DecodeURL(Request.QueryString("Product_Id")), pageCounter)
            fillURL(DecodeURL(Request.QueryString("Product_Id")))
        End If

        If Request.QueryString("Product_DId") = Nothing Then
        Else
            CategorySelectedInfo(Request.QueryString("Product_DId"), pageCounter)
            fillURL(Request.QueryString("Product_DId"))
        End If

        If Request.QueryString("key") = Nothing Then
        Else
            search_product(pageCounter)
        End If

        If Label1.Visible = True Then
            lnkInquiry.Attributes.Add("onclick", "return OpenInquery();")
        End If
    End Sub

    Protected Sub lbtnBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtnBack.Click
        Dim pageCounter As Integer
        If txtCounter.Text = "" Or txtCounter.Text Is Nothing Or txtCounter.Text = "0" Then
            pageCounter = 0
            txtCounter.Text = "1"
        Else
            pageCounter = CType(txtCounter.Text.ToString, Integer) - 1
        End If

        pageCounter = pageCounter - 1
        If pageCounter = gvProductDisplay.PageCount Then
            txtCounter.Text = pageCounter
        Else
            txtCounter.Text = pageCounter + 1
        End If

        If pageCounter = 0 And gvProductDisplay.PageCount = 1 Then
            lbtnBack.Visible = False
            lbtnNext.Visible = False
        Else
            If pageCounter = 0 Then
                lbtnBack.Visible = False
                lbtnNext.Visible = True
                txtCounter.Text = "1"
            ElseIf pageCounter >= 1 And pageCounter < gvProductDisplay.PageCount - 1 Then
                lbtnBack.Visible = True
                lbtnNext.Visible = True
            ElseIf pageCounter = gvProductDisplay.PageCount - 1 Or pageCounter >= gvProductDisplay.PageCount Then
                lbtnBack.Visible = True
                lbtnNext.Visible = False
                txtCounter.Text = gvProductDisplay.PageCount
            End If
        End If

        If IsNothing(CatDistinct) Then
            GetCatDistinct()
        End If
        dtCategoryDistinct = CatDistinct

        If Request.QueryString("Product_KId") = Nothing Then
        Else
            productinfo(pageCounter)
            fillURL(CType(Session("Product"), DataTable).Rows(0)("Product_CategoryId").ToString)
        End If

        If Request.QueryString("Brand_KId") = Nothing Then
            Session("brandid") = Nothing
        Else
            Session("brandid") = DecodeURL(Request.QueryString("Brand_KId"))
            BrandSelectedInfo(pageCounter)
        End If

        If Request.QueryString("Product_HId") = Nothing Then
        Else
            Session("catid") = DecodeURL(Request.QueryString("Product_HId"))
            CategorySelectedInfoHead(DecodeURL(Request.QueryString("Product_HId")), pageCounter)
            fillURL(DecodeURL(Request.QueryString("Product_HId")))
        End If

        If Request.QueryString("Product_Id") = Nothing Then
        Else
            Session("catid") = DecodeURL(Request.QueryString("Product_Id"))
            CategorySelectedInfo(DecodeURL(Request.QueryString("Product_Id")), pageCounter)
            fillURL(DecodeURL(Request.QueryString("Product_Id")))
        End If

        If Request.QueryString("Product_DId") = Nothing Then
        Else
            CategorySelectedInfo(Request.QueryString("Product_DId"), pageCounter)
            fillURL(Request.QueryString("Product_DId"))
        End If

        If Request.QueryString("key") = Nothing Then
        Else
            search_product(pageCounter)
        End If

        If Label1.Visible = True Then
            lnkInquiry.Attributes.Add("onclick", "return OpenInquery();")
        End If
    End Sub '------End update------
#End Region

#Region "Methods"
    Public Sub fillURL(ByVal Cat_KID As String)
        Dim dr() As DataRow
        dr = dtCategoryDistinct.Select("Category_KId='" & Cat_KID & "'")
        Dim url As String
        url = ""
        If dr.Length = 0 Then
            tdURL.InnerHtml += "<a href='" & ResolveUrl("~/main/" & EncodeURL(RemoveLiterals(Cat_KID.ToString)) & "/" & ReturnValue("Select CategoryName from Category_Distinct where Category_Kid='" & RemoveLiterals(Cat_KID.ToString) & "'") & ".aspx") & "' >" & ReturnValue("Select Category_Name from Category_Distinct where Category_KId ='" & RemoveLiterals(Cat_KID.ToString) & "'") & "</a> > "
            Session("MainCat") = RemoveLiterals(Cat_KID.ToString)
            Exit Sub
        Else
            Dim dr1() As DataRow
            dr1 = dr
            While dr1.Length <> 0
                url += "<a href='" & ResolveUrl("~/JJJ/" & EncodeURL(dr(0).Item("Category_Kid").ToString) & "/" & dr(0).Item("ParentName").ToString & "/" & dr(0).Item("CategoryName").ToString & ".aspx") & "' > " & dr(0).Item("Category_Name").ToString & "</a> > | "
                dr = dtCategoryDistinct.Select("Category_KId='" & dr1(0).Item("Category_ParentId") & "'")
                If dr.Length = 0 Then
                    url += "<a href='" & ResolveUrl("~/main/" & EncodeURL(RemoveLiterals(dr1(0).Item("Category_ParentId"))) & "/" & dr1(0).Item("ParentName").ToString & ".aspx") & "' >" & dr1(0).Item("Category_ParentName").ToString & "</a> > "
                End If
                dr1 = dr
            End While
        End If

        tdURL.InnerHtml = "<a href='http://www.atcomaart.com'> <b>Product Category  </b></a> > <span style='color:#155799'>"
        Dim url1() As String
        url1 = url.Split("|")
        Array.Reverse(url1)

        Dim i As Integer
        For i = 0 To url1.Length - 1
            If i = 0 Then
                tdURL.InnerHtml += url1(0).ToString
                Continue For
            Else
                If i = url1.Length - 1 Then
                    If Request.QueryString("Product_HId") = Nothing Then
                        tdURL.InnerHtml += url1(i).Replace("JJJ", "category")
                    Else
                        tdURL.InnerHtml += url1(i).Replace("JJJ", "s" & i + 1)
                    End If
                Else
                    tdURL.InnerHtml += url1(i).Replace("JJJ", "s" & i + 1)
                End If
            End If
        Next
    End Sub

    Private Sub CategorySelectedInfoHead(ByVal KID As String, ByVal pageCounter As Integer)
        Try
            If Request.QueryString("page") = Nothing Then
                Session("CategoryHead") = Nothing
            End If
            Dim strProductName As String
            If IsNothing(Session("CategoryHead")) Then
                Dim con As New SqlConnection
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                Try
                    cmd = New SqlCommand("SELECT ProductDisplay.Product_Kid, ProductDisplay.Product_Code, ProductDisplay.Product_Name, ProductDisplay.Product_ModelNo,ProductDisplay.Product_MarketPrice, ProductDisplay.Brand_Name, ProductDisplay.Product_Image, ProductDisplay.Product_BrandId,ProductDisplay.Product_Approved, ProductDisplay.Product_Description, ProductDisplay.CatName, ProductDisplay.ProdName,ProductDisplay.Product_CategoryId, ProductDisplay.Product_RegDate, ProductDisplay.Product_IsWear_Tear, ProductDisplay.Product_MarketPrice,Category_Index_Master.CategoryIndex_Name, Category_Index_Master.CategoryIndex_IsDeleted FROM ProductDisplay INNER JOIN Category_Index_Master ON ProductDisplay.Product_CategoryId = Category_Index_Master.Category_Kid WHERE (ProductDisplay.Product_CategoryId IN (SELECT Category_Kid FROM Category_Master WHERE (Category_ParentId = '" & RemoveLiterals(DecodeURL(Request.QueryString("Product_HId").ToString).ToString) & "') AND (Category_IsDeleted = N'0'))) AND (Category_Index_Master.CategoryIndex_Name = '" & ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("Product_Index").ToString.Trim & "'").ToString.Trim & "') AND (Category_Index_Master.CategoryIndex_IsDeleted = N'0') ORDER BY ProductDisplay.Product_Name, Product_Code", con)
                    con.Open()
                    da = New SqlDataAdapter(cmd)
                    da.Fill(ds, "CategoryHead")
                    Session("CategoryHead") = ds.Tables("CategoryHead")
                Catch ex As Exception

                End Try
            End If
            Dim dt As DataTable
            dt = CType(Session("CategoryHead"), DataTable).DefaultView.ToTable
            If Request.QueryString("page") <> Nothing Then
                Dim dtPage As New DataTable
                dtPage = dt.Clone

                Dim currentstart As Integer
                Dim currentend As Integer
                currentstart = ((CType(Request.QueryString("page"), Integer) - 1) * 10)
                currentend = currentstart + 11
                While currentstart <> currentend
                    Try
                        dtPage.Rows.Add(dt.Rows(currentstart).ItemArray)
                        currentstart = currentstart + 1
                    Catch ex As Exception
                        currentstart = currentend
                    End Try
                End While

                ItemFound.Text = ""
                Dim dt_catname As DataTable = SelectCategory_BrandName("Category_KId", KID)
                strProductName = dt_catname.Rows(0).Item(0).ToString
                ItemFound.Text = CType(Session("CategoryHead"), DataTable).Rows.Count & " Item(s) Found in  " & strProductName & " Category."

                Dim gvPageCount As Integer
                gvPageCount = gvProductDisplay.PageCount
                lblPageCounter.Text = gvPageCount.ToString
                If pageCounter = 0 Then
                    gvProductDisplay.PageIndex = 0
                ElseIf pageCounter >= gvPageCount Then
                    gvProductDisplay.PageIndex = gvPageCount
                ElseIf pageCounter < gvPageCount Then
                    gvProductDisplay.PageIndex = pageCounter
                End If
                gvProductDisplay.DataSource = dtPage.DefaultView.ToTable
                gvProductDisplay.DataBind()

                Dim count As Integer
                For count = 0 To gvProductDisplay.Rows.Count - 1
                    Dim imgpath As String
                    imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dtPage.Rows(count).Item("Product_Image").ToString())
                    KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                Next

                'If dtPage.Rows.Count <= 10 Then
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                'Else
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                'End If

                'If Request.QueryString("page") = 1 Then
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                'End If

                'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?page")) & "?page=" & CType(Request.QueryString("page"), Integer) - 1)
                'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?page")) & "?page=" & CType(Request.QueryString("page"), Integer) + 1)
                ItemFound.Visible = True
                imgbtnCompare.Visible = True
                imglbtnAddtoWiseList.Visible = True
                Label1.Visible = False
                lnkInquiry.Visible = False
                Label2.Visible = True
                Exit Sub
            End If

            If dt.DefaultView.ToTable.Rows.Count > 0 Then
                ItemFound.Text = ""
                Dim dt_catname1 As DataTable = SelectCategory_BrandName("Category_KId", KID)
                strProductName = dt_catname1.Rows(0).Item(0).ToString
                ItemFound.Text = CType(Session("CategoryHead"), DataTable).Rows.Count & " Item(s) Found in  " & strProductName & " Category."

                Dim gvPageCount As Integer
                gvPageCount = gvProductDisplay.PageCount
                lblPageCounter.Text = gvPageCount.ToString
                If pageCounter = 0 Then
                    gvProductDisplay.PageIndex = 0
                ElseIf pageCounter >= gvPageCount Then
                    gvProductDisplay.PageIndex = gvPageCount
                ElseIf pageCounter < gvPageCount Then
                    gvProductDisplay.PageIndex = pageCounter
                End If
                gvProductDisplay.DataSource = dt.DefaultView.ToTable
                gvProductDisplay.DataBind()

                Dim count As Integer
                For count = 0 To gvProductDisplay.Rows.Count - 1
                    Dim imgpath As String
                    imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dt.DefaultView.ToTable.Rows(count).Item("Product_Image").ToString())
                    KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                Next

                'If Request.QueryString("page") = Nothing Then
                '    If dt.DefaultView.Table.Rows.Count < 10 Then
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                '    Else
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl & "?page=2")
                '    End If
                'Else
                '    If dt.DefaultView.ToTable.Rows.Count < 10 Then
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                '    Else
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                '    End If
                '    If Request.QueryString("page") = 1 Then
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                '    End If
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?page")) & "?page=" & CType(Request.QueryString("page"), Integer) - 1)
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?page")) & "?page=" & CType(Request.QueryString("page"), Integer) + 1)
                'End If
                ItemFound.Visible = True
                imgbtnCompare.Visible = True
                imglbtnAddtoWiseList.Visible = True
                stirp.Visible = True
                Label1.Visible = False
                lnkInquiry.Visible = False
                Label2.Visible = True
            Else
                Dim dt_catname2 As DataTable = SelectCategory_BrandName("Category_KId", KID)
                strProductName = dt_catname2.Rows(0).Item(0).ToString
                ItemFound.Visible = False
                imgbtnCompare.Visible = False
                imglbtnAddtoWiseList.Visible = False
                lbl1.Visible = False
                txtCounter.Visible = False
                lbl2.Visible = False
                lblPageCounter.Visible = False
                lbtnBack.Visible = False
                lbtnNext.Visible = False
                stirp.Visible = False
                Label1.Visible = True
                Label4.Text = "<img alt='' src='" & Page.ResolveUrl("~/Images/javascripts.gif") & "'/>&nbsp; We Are registering products for <b> " & strProductName & " </b> category ! and will be up soon...<br /> For more details please Fill Up Your&nbsp; <strong>inquiry</strong>..."
                lnkInquiry.Visible = True
                Label2.Visible = False
                ds.Clear()
            End If
            con.Close()
        Catch ex As Exception
            ex.Message.ToString()
        End Try
    End Sub

    Private Sub CategorySelectedInfo(ByVal KID As String, ByVal pageCounter As Integer)
        Try
            If Request.QueryString("page") = Nothing Then
                Session("Category") = Nothing
            End If

            Dim strProductName As String
            If IsNothing(Session("Category")) Then
                Dim con As New SqlConnection
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                Dim dt_cat As DataTable
                dt_cat = ReturnDataTable("SELECT  distinct   ProductDisplay.* FROM         ProductDisplay LEFT OUTER JOIN                       ProductCategory_Master ON ProductDisplay.Product_CategoryId = ProductCategory_Master.ProductCategory_CategoryID WHERE     (ProductDisplay.Product_Approved = N'Y') AND (ProductDisplay.Product_Kid IN                           (SELECT     ProductCategory_ProductID                             FROM          ProductCategory_Master AS ProductCategory_Master_1                             WHERE      (ProductCategory_CategoryID = N'" & RemoveLiterals(KID) & "'))) OR                       (ProductDisplay.Product_Approved = N'Y') AND (ProductDisplay.Product_CategoryId = N'" & RemoveLiterals(KID) & "') Order by Product_Name, Product_Code")
                Session("Category") = dt_cat
            End If

            Dim dt As DataTable
            dt = CType(Session("Category"), DataTable).DefaultView.ToTable
            If Request.QueryString("page") <> Nothing Then
                Dim dtPage As New DataTable
                dtPage = dt.Clone
                Dim currentstart As Integer
                Dim currentend As Integer
                currentstart = ((CType(Request.QueryString("page"), Integer) - 1) * 10)
                currentend = currentstart + 11

                While currentstart <> currentend
                    Try
                        dtPage.Rows.Add(dt.Rows(currentstart).ItemArray)
                        currentstart = currentstart + 1
                    Catch ex As Exception
                        currentstart = currentend
                    End Try
                End While

                ItemFound.Text = ""
                Dim dt_catname3 As DataTable = SelectCategory_BrandName("Category_KId", KID)
                strProductName = dt_catname3.Rows(0).Item(0).ToString
                ItemFound.Text = CType(Session("Category"), DataTable).Rows.Count & " Item(s) Found in  " & strProductName & " Category."

                Dim gvPageCount As Integer
                gvPageCount = gvProductDisplay.PageCount
                lblPageCounter.Text = gvPageCount.ToString
                If pageCounter = 0 Then
                    gvProductDisplay.PageIndex = 0
                ElseIf pageCounter >= gvPageCount Then
                    gvProductDisplay.PageIndex = gvPageCount
                ElseIf pageCounter < gvPageCount Then
                    gvProductDisplay.PageIndex = pageCounter
                End If
                gvProductDisplay.DataSource = dtPage.DefaultView.ToTable
                gvProductDisplay.DataBind()

                Dim count As Integer
                For count = 0 To gvProductDisplay.Rows.Count - 1
                    Dim imgpath As String
                    imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dtPage.Rows(count).Item("Product_Image").ToString())
                    KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                Next

                'If dtPage.Rows.Count <= 10 Then
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                'Else
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                'End If
                'If Request.QueryString("page") = 1 Then
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                'End If
                'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?page")) & "?page=" & CType(Request.QueryString("page"), Integer) - 1)
                'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?page")) & "?page=" & CType(Request.QueryString("page"), Integer) + 1)
                ItemFound.Visible = True
                imgbtnCompare.Visible = True
                imglbtnAddtoWiseList.Visible = True
                Label1.Visible = False
                lnkInquiry.Visible = False
                Label2.Visible = True
                Exit Sub
            End If

            If dt.DefaultView.ToTable.Rows.Count > 0 Then
                ItemFound.Text = ""
                Dim dt_catname4 As DataTable = SelectCategory_BrandName("Category_KId", KID)
                strProductName = dt_catname4.Rows(0).Item(0).ToString
                ItemFound.Text = CType(Session("Category"), DataTable).Rows.Count & " Item(s) Found in  " & strProductName & " Category."

                Dim gvPageCount As Integer
                gvPageCount = gvProductDisplay.PageCount
                lblPageCounter.Text = gvPageCount.ToString
                If pageCounter = 0 Then
                    gvProductDisplay.PageIndex = 0
                ElseIf pageCounter >= gvPageCount Then
                    gvProductDisplay.PageIndex = gvPageCount
                ElseIf pageCounter < gvPageCount Then
                    gvProductDisplay.PageIndex = pageCounter
                End If
                gvProductDisplay.DataSource = dt.DefaultView.ToTable
                gvProductDisplay.DataBind()

                Dim count As Integer
                For count = 0 To gvProductDisplay.Rows.Count - 1
                    Dim imgpath As String
                    imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dt.DefaultView.ToTable.Rows(count).Item("Product_Image").ToString())
                    KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                Next

                'If Request.QueryString("page") = Nothing Then
                '    If dt.DefaultView.Table.Rows.Count <= 10 Then
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                '    Else
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl & "?page=2")
                '    End If
                'Else
                '    If dt.DefaultView.ToTable.Rows.Count < 10 Then
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                '    Else
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                '    End If
                '    If Request.QueryString("page") = 1 Then
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                '    End If
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?page")) & "?page=" & CType(Request.QueryString("page"), Integer) - 1)
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?page")) & "?page=" & CType(Request.QueryString("page"), Integer) + 1)
                'End If

                ItemFound.Visible = True
                imgbtnCompare.Visible = True
                imglbtnAddtoWiseList.Visible = True
                stirp.Visible = True
                Label1.Visible = False
                lnkInquiry.Visible = False
                Label2.Visible = True
            Else
                Dim dt_catname5 As DataTable = SelectCategory_BrandName("Category_KId", KID)
                strProductName = dt_catname5.Rows(0).Item(0).ToString
                ItemFound.Visible = False
                imgbtnCompare.Visible = False
                imglbtnAddtoWiseList.Visible = False
                lbl1.Visible = False
                txtCounter.Visible = False
                lbl2.Visible = False
                lblPageCounter.Visible = False
                lbtnBack.Visible = False
                lbtnNext.Visible = False
                stirp.Visible = False
                Label1.Visible = True
                Label4.Text = "<img alt='' src='" & Page.ResolveUrl("~/Images/javascripts.gif") & "'/>&nbsp; We Are registering products for <b> " & strProductName & " </b> category ! and will be up soon...<br /> For more details please Fill Up Your&nbsp; <strong>inquiry</strong>..."
                lnkInquiry.Visible = True
                Label2.Visible = False
                ds.Clear()
            End If
            con.Close()

        Catch ex As Exception
            ex.Message.ToString()
        End Try
    End Sub

    Private Sub productinfo(ByVal pageCounter As Integer)
        Try
            If Request.QueryString("page") = Nothing Then
                Session("Product") = Nothing
            End If

            If IsNothing(Session("Product")) Then
                Dim strCat As String
                strCat = Request.QueryString("Product_CatID").ToString
                Try
                    strCat = strCat.Remove(0, strCat.IndexOf("/") + 1)
                Catch ex As Exception
                    strCat = Request.QueryString("Product_CatID").ToString
                End Try

                Dim Product_Name As String
                Product_Name = ReturnValue("Select OriginalProduct_Name from Product_Distinct where Product_Name ='" & Request.QueryString("Product_KID").ToString & "'and Category_Name ='" & strCat & "'")
                If Product_Name = "" Then
                    Product_Name = Request.QueryString("Product_KID").ToString.Replace("'", "").Replace("--", "")
                End If

                Dim con As New SqlConnection
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                cmd = New SqlCommand("select ProductDisplay.* from ProductDisplay where (ProductDisplay.Product_Name LIKE '%" & Product_Name.Trim.Replace("'", "") & "%') order by Product_Name, Product_Code", con)
                con.Open()
                da = New SqlDataAdapter(cmd)
                da.Fill(ds, "Product_Mast")
                Session("Product") = ds.Tables("Product_Mast")
            End If

            Dim dt As DataTable
            dt = CType(Session("Product"), DataTable).DefaultView.ToTable
            If Request.QueryString("page") <> Nothing Then
                Dim dtPage As New DataTable
                dtPage = dt.Clone

                Dim currentstart As Integer
                Dim currentend As Integer
                currentstart = ((CType(Request.QueryString("page"), Integer) - 1) * 10)
                currentend = currentstart + 11
                While currentstart <> currentend
                    Try
                        dtPage.Rows.Add(dt.Rows(currentstart).ItemArray)
                        currentstart = currentstart + 1
                    Catch ex As Exception
                        currentstart = currentend
                    End Try
                End While

                ItemFound.Text = ""
                ItemFound.Text = dt.Rows.Count & " Item(s) Found for  " & Request.QueryString("Product_KId").Replace("-", " ") & "."

                Dim gvPageCount As Integer
                gvPageCount = gvProductDisplay.PageCount
                lblPageCounter.Text = gvPageCount.ToString
                If pageCounter = 0 Then
                    gvProductDisplay.PageIndex = 0
                ElseIf pageCounter >= gvPageCount Then
                    gvProductDisplay.PageIndex = gvPageCount
                ElseIf pageCounter < gvPageCount Then
                    gvProductDisplay.PageIndex = pageCounter
                End If
                gvProductDisplay.DataSource = dtPage.DefaultView.ToTable
                gvProductDisplay.DataBind()

                Dim count As Integer
                For count = 0 To gvProductDisplay.Rows.Count - 1
                    Dim imgpath As String
                    imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dtPage.Rows(count).Item("Product_Image").ToString())
                    KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                Next

                'If dtPage.Rows.Count <= 10 Then
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                'Else
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                'End If
                'If Request.QueryString("page") = 1 Then
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                'End If
                'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?page")) & "?page=" & CType(Request.QueryString("page"), Integer) - 1)
                'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?page")) & "?page=" & CType(Request.QueryString("page"), Integer) + 1)
                ItemFound.Visible = True
                imgbtnCompare.Visible = True
                imglbtnAddtoWiseList.Visible = True
                Label1.Visible = False
                lnkInquiry.Visible = False
                Label2.Visible = True
                Exit Sub
            End If

            If dt.DefaultView.ToTable.Rows.Count > 0 Then
                ItemFound.Text = ""
                ItemFound.Text = dt.Rows.Count & " Item(s) Found for  " & Request.QueryString("Product_KId").Replace("-", " ") & "."

                Dim gvPageCount As Integer
                gvPageCount = gvProductDisplay.PageCount
                lblPageCounter.Text = gvPageCount.ToString
                If pageCounter = 0 Then
                    gvProductDisplay.PageIndex = 0
                ElseIf pageCounter >= gvPageCount Then
                    gvProductDisplay.PageIndex = gvPageCount
                ElseIf pageCounter < gvPageCount Then
                    gvProductDisplay.PageIndex = pageCounter
                End If
                gvProductDisplay.DataSource = dt.DefaultView.ToTable
                gvProductDisplay.DataBind()

                Dim count As Integer
                For count = 0 To gvProductDisplay.Rows.Count - 1
                    Dim imgpath As String
                    imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dt.DefaultView.ToTable.Rows(count).Item("Product_Image").ToString())
                    KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                Next

                'If Request.QueryString("page") = Nothing Then
                '    If dt.DefaultView.Table.Rows.Count <= 10 Then
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                '    Else
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl & "?page=2")
                '    End If
                'Else
                '    If dt.DefaultView.ToTable.Rows.Count <= 10 Then
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                '    Else
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                '    End If
                '    If Request.QueryString("page") = 1 Then
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                '    End If
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?page")) & "?page=" & CType(Request.QueryString("page"), Integer) - 1)
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?page")) & "?page=" & CType(Request.QueryString("page"), Integer) + 1)
                'End If
                ItemFound.Visible = True
                imgbtnCompare.Visible = True
                imglbtnAddtoWiseList.Visible = True
                stirp.Visible = True
                Label1.Visible = False
                lnkInquiry.Visible = False
                Label2.Visible = True
            Else
                ItemFound.Visible = False
                imgbtnCompare.Visible = False
                imglbtnAddtoWiseList.Visible = False
                lbl1.Visible = False
                txtCounter.Visible = False
                lbl2.Visible = False
                lblPageCounter.Visible = False
                lbtnBack.Visible = False
                lbtnNext.Visible = False
                stirp.Visible = False
                Label1.Visible = True
                Label4.Text = "<img alt='' src='" & Page.ResolveUrl("~/Images/javascripts.gif") & "'/>&nbsp; We Are registering products for <b> " & Request.QueryString("Product_KId").Replace("-", " ") & " </b> search ! and will be up soon...<br /> For more details please Fill Up Your&nbsp; <strong>inquiry</strong>..."
                lnkInquiry.Visible = True
                Label2.Visible = False
                ds.Clear()
            End If
            con.Close()
        Catch ex As Exception
            ex.Message.ToString()
        End Try
    End Sub

    Private Sub BrandSelectedInfo(ByVal pageCounter As Integer)
        Try
            Dim brandname As String
            If Request.QueryString("page") = Nothing Then
                Session("Brand") = Nothing
            End If

            If IsNothing(Session("Brand")) Then
                Dim con As New SqlConnection
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")

                Dim dt_brand As DataTable
                dt_brand = GetProductInformation("Product_BrandId", DecodeURL(Request.QueryString("Brand_KId")))
                Session("Brand") = dt_brand
            End If

            Dim dt As DataTable
            dt = CType(Session("Brand"), DataTable).DefaultView.ToTable
            If Request.QueryString("page") <> Nothing Then
                Dim dtPage As New DataTable
                dtPage = dt.Clone

                Dim currentstart As Integer
                Dim currentend As Integer
                currentstart = ((CType(Request.QueryString("page"), Integer) - 1) * 10)
                currentend = currentstart + 11
                While currentstart <> currentend
                    Try
                        dtPage.Rows.Add(dt.Rows(currentstart).ItemArray)
                        currentstart = currentstart + 1
                    Catch ex As Exception
                        currentstart = currentend
                    End Try
                End While

                ItemFound.Text = ""
                Dim dt_brand As DataTable = SelectCategory_BrandName("Brand_KId", DecodeURL(Request.QueryString("Brand_KId")))
                brandname = dt_brand.Rows(0).Item(0).ToString
                ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & brandname & " Brand."

                Dim gvPageCount As Integer
                gvPageCount = gvProductDisplay.PageCount
                lblPageCounter.Text = gvPageCount.ToString
                If pageCounter = 0 Then
                    gvProductDisplay.PageIndex = 0
                ElseIf pageCounter >= gvPageCount Then
                    gvProductDisplay.PageIndex = gvPageCount
                ElseIf pageCounter < gvPageCount Then
                    gvProductDisplay.PageIndex = pageCounter
                End If
                gvProductDisplay.DataSource = dtPage.DefaultView.ToTable
                gvProductDisplay.DataBind()

                Dim count As Integer
                For count = 0 To gvProductDisplay.Rows.Count - 1
                    Dim imgpath As String
                    imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dtPage.Rows(count).Item("Product_Image").ToString())
                    KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                Next

                'If dtPage.Rows.Count <= 10 Then
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                'Else
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                'End If

                'If Request.QueryString("page") = 1 Then
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                'End If

                'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?page")) & "?page=" & CType(Request.QueryString("page"), Integer) - 1)
                'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?page")) & "?page=" & CType(Request.QueryString("page"), Integer) + 1)
                ItemFound.Visible = True
                imgbtnCompare.Visible = True
                imglbtnAddtoWiseList.Visible = True
                Label1.Visible = False
                lnkInquiry.Visible = False
                Label2.Visible = True
                Exit Sub
            End If

            If dt.DefaultView.ToTable.Rows.Count > 0 Then
                ItemFound.Text = ""
                Dim dt_brand1 As DataTable = SelectCategory_BrandName("Brand_KId", DecodeURL(Request.QueryString("Brand_KId")))
                brandname = dt_brand1.Rows(0).Item(0).ToString
                ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & brandname & " Brand."

                Dim gvPageCount As Integer
                gvPageCount = gvProductDisplay.PageCount
                lblPageCounter.Text = gvPageCount.ToString
                If pageCounter = 0 Then
                    gvProductDisplay.PageIndex = 0
                ElseIf pageCounter >= gvPageCount Then
                    gvProductDisplay.PageIndex = gvPageCount
                ElseIf pageCounter < gvPageCount Then
                    gvProductDisplay.PageIndex = pageCounter
                End If
                gvProductDisplay.DataSource = dt.DefaultView.ToTable
                gvProductDisplay.DataBind()


                Dim count As Integer
                For count = 0 To gvProductDisplay.Rows.Count - 1
                    Dim imgpath As String
                    imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dt.DefaultView.ToTable.Rows(count).Item("Product_Image").ToString())
                    KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                Next

                'If Request.QueryString("page") = Nothing Then
                '    If dt.DefaultView.Table.Rows.Count <= 10 Then
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                '    Else
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl & "?page=2")
                '    End If
                'Else
                '    If dt.DefaultView.ToTable.Rows.Count <= 10 Then
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                '    Else
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                '    End If
                '    If Request.QueryString("page") = 1 Then
                '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                '    End If
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?page")) & "?page=" & CType(Request.QueryString("page"), Integer) - 1)
                '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?page")) & "?page=" & CType(Request.QueryString("page"), Integer) + 1)
                'End If

                ItemFound.Visible = True
                imgbtnCompare.Visible = True
                imglbtnAddtoWiseList.Visible = True
                stirp.Visible = True
                Label1.Visible = False
                lnkInquiry.Visible = False
                Label2.Visible = True
            Else
                Dim dt_brand2 As DataTable = SelectCategory_BrandName("Brand_KId", DecodeURL(Request.QueryString("Brand_KId")))
                brandname = dt_brand2.Rows(0).Item(0).ToString
                ItemFound.Visible = False
                imgbtnCompare.Visible = False
                imglbtnAddtoWiseList.Visible = False
                lbl1.Visible = False
                txtCounter.Visible = False
                lbl2.Visible = False
                lblPageCounter.Visible = False
                lbtnBack.Visible = False
                lbtnNext.Visible = False
                stirp.Visible = False
                Label1.Visible = True
                Label4.Text = "<img alt='' src='" & Page.ResolveUrl("~/Images/javascripts.gif") & "'/>&nbsp; We Are registering products for  <b>" & brandname & "</b>   brand ! and will be up soon...<br />please Fill Up Your&nbsp; <strong>inquiry</strong>..."
                lnkInquiry.Visible = True
                Label2.Visible = False
                ds.Clear()
            End If
            con.Close()
        Catch ex As Exception
            ex.Message.ToString()
        End Try
    End Sub

    Private Sub search_product(ByVal pageCounter As Integer)
        Try
            If Request.QueryString("Value") = 0 Then
                If Request.QueryString("page") = Nothing Then
                    Session("Search0") = Nothing
                End If

                If IsNothing(Session("Search0")) Then
                    Dim con As New SqlConnection
                    Dim ds As New DataSet
                    con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                    strr = "select ProductDisplay.* from ProductDisplay where product_kid in (select Keyword_ProductId from Product_Keyword where Keyword_Name like '%" & Request.QueryString("key") & "%') or Product_Name Like '%" & Request.QueryString("key") & "%' or Product_ModelNo Like '%" & Request.QueryString("key") & "%' or CatName Like '%" & Request.QueryString("key") & "%' or Product_Description Like '%" & Request.QueryString("key") & "%' or product_Brandid in (SELECT Brand_Kid FROM  Brand_Master WHERE (Brand_IsDeleted = N'0') AND (Brand_Name like '%" & Request.QueryString("key") & "%'))  order by Product_Name, Product_code"
                    cmd = New SqlCommand(strr, con)
                    Dim da As New SqlDataAdapter(cmd)
                    da.Fill(ds, "Info")
                    Session("Search0") = ds.Tables("Info")
                End If

                dt = CType(Session("Search0"), DataTable).DefaultView.ToTable
                If Request.QueryString("page") <> Nothing Then
                    Dim dtPage As New DataTable
                    dtPage = dt.Clone
                    Dim currentstart As Integer
                    Dim currentend As Integer
                    currentstart = ((CType(Request.QueryString("page"), Integer) - 1) * 10)
                    currentend = currentstart + 11
                    While currentstart <> currentend
                        Try
                            dtPage.Rows.Add(dt.Rows(currentstart).ItemArray)
                            currentstart = currentstart + 1
                        Catch ex As Exception
                            currentstart = currentend
                        End Try
                    End While

                    ItemFound.Text = ""
                    ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."

                    Dim gvPageCount As Integer
                    gvPageCount = gvProductDisplay.PageCount
                    lblPageCounter.Text = gvPageCount.ToString
                    If pageCounter = 0 Then
                        gvProductDisplay.PageIndex = 0
                    ElseIf pageCounter >= gvPageCount Then
                        gvProductDisplay.PageIndex = gvPageCount
                    ElseIf pageCounter < gvPageCount Then
                        gvProductDisplay.PageIndex = pageCounter
                    End If
                    gvProductDisplay.DataSource = dtPage.DefaultView.ToTable
                    gvProductDisplay.DataBind()

                    If dt.Rows.Count = 1 Then
                        fillURL(dt.Rows(0).Item("Product_CategoryId").ToString)
                    Else
                        tdURL.InnerHtml = "&nbsp;"
                    End If

                    Dim count As Integer
                    For count = 0 To gvProductDisplay.Rows.Count - 1
                        Dim imgpath As String
                        imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dtPage.Rows(count).Item("Product_Image").ToString())
                        KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                    Next

                    'If dt.DefaultView.ToTable.Rows.Count <= 10 Then
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                    'Else
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                    'End If

                    'If Request.QueryString("page") = 1 Then
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                    'End If

                    'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) - 1)
                    'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) + 1)
                    ItemFound.Visible = True
                    imgbtnCompare.Visible = True
                    imglbtnAddtoWiseList.Visible = True
                    stirp.Visible = True
                    Label1.Visible = False
                    lnkInquiry.Visible = False
                    Label2.Visible = True
                    Exit Sub
                End If

                If dt.DefaultView.ToTable.Rows.Count > 0 Then
                    ItemFound.Text = ""
                    ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."

                    Dim gvPageCount As Integer
                    gvPageCount = gvProductDisplay.PageCount
                    lblPageCounter.Text = gvPageCount.ToString
                    If pageCounter = 0 Then
                        gvProductDisplay.PageIndex = 0
                    ElseIf pageCounter >= gvPageCount Then
                        gvProductDisplay.PageIndex = gvPageCount
                    ElseIf pageCounter < gvPageCount Then
                        gvProductDisplay.PageIndex = pageCounter
                    End If
                    gvProductDisplay.DataSource = dt.DefaultView.ToTable
                    gvProductDisplay.DataBind()

                    If dt.Rows.Count = 1 Then
                        fillURL(dt.Rows(0).Item("Product_CategoryId").ToString)
                    Else
                        tdURL.InnerHtml = "&nbsp;"
                    End If

                    Dim count As Integer
                    For count = 0 To gvProductDisplay.Rows.Count - 1
                        Dim imgpath As String
                        imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dt.DefaultView.ToTable.Rows(count).Item("Product_Image").ToString())
                        KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                    Next

                    'If Request.QueryString("page") = Nothing Then
                    '    If dt.DefaultView.Table.Rows.Count <= 10 Then
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                    '    Else
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl & "&page=2")
                    '    End If
                    'Else
                    '    If dt.DefaultView.ToTable.Rows.Count <= 10 Then
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                    '    Else
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                    '    End If

                    '    If Request.QueryString("page") = 1 Then
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                    '    End If
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) - 1)
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) + 1)
                    'End If

                    ItemFound.Visible = True
                    imgbtnCompare.Visible = True
                    imglbtnAddtoWiseList.Visible = True
                    stirp.Visible = True
                    Label1.Visible = False
                    lnkInquiry.Visible = False
                    Label2.Visible = True
                End If
            ElseIf Request.QueryString("Value") = 1 Then
                If Request.QueryString("page") = Nothing Then
                    Session("Search1") = Nothing
                End If

                If IsNothing(Session("Search1")) Then
                    Dim con As New SqlConnection
                    con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                    dt1 = GetProductInformation("Product_ModelNo", Request.QueryString("Key"))
                    Session("Search1") = dt1
                End If

                dt = CType(Session("Search1"), DataTable).DefaultView.ToTable
                If Request.QueryString("page") <> Nothing Then
                    Dim dtPage As New DataTable
                    dtPage = dt.Clone
                    Dim currentstart As Integer
                    Dim currentend As Integer
                    currentstart = ((CType(Request.QueryString("page"), Integer) - 1) * 10)
                    currentend = currentstart + 11
                    While currentstart <> currentend
                        Try
                            dtPage.Rows.Add(dt.Rows(currentstart).ItemArray)
                            currentstart = currentstart + 1
                        Catch ex As Exception
                            currentstart = currentend
                        End Try
                    End While

                    ItemFound.Text = ""
                    ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."

                    Dim gvPageCount As Integer
                    gvPageCount = gvProductDisplay.PageCount
                    lblPageCounter.Text = gvPageCount.ToString
                    If pageCounter = 0 Then
                        gvProductDisplay.PageIndex = 0
                    ElseIf pageCounter >= gvPageCount Then
                        gvProductDisplay.PageIndex = gvPageCount
                    ElseIf pageCounter < gvPageCount Then
                        gvProductDisplay.PageIndex = pageCounter
                    End If
                    gvProductDisplay.DataSource = dtPage.DefaultView.ToTable
                    gvProductDisplay.DataBind()

                    If dt.Rows.Count = 1 Then
                        fillURL(dt.Rows(0).Item("Product_CategoryId").ToString)
                    Else
                        tdURL.InnerHtml = "&nbsp;"
                    End If

                    Dim count As Integer
                    For count = 0 To gvProductDisplay.Rows.Count - 1
                        Dim imgpath As String
                        imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dtPage.Rows(count).Item("Product_Image").ToString())
                        KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                    Next

                    'If dt.DefaultView.ToTable.Rows.Count <= 10 Then
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                    'Else
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                    'End If

                    'If Request.QueryString("page") = 1 Then
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                    'End If

                    'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) - 1)
                    'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) + 1)
                    ItemFound.Visible = True
                    imgbtnCompare.Visible = True
                    imglbtnAddtoWiseList.Visible = True
                    stirp.Visible = True
                    Label1.Visible = False
                    lnkInquiry.Visible = False
                    Label2.Visible = True
                    Exit Sub
                End If
                If dt.DefaultView.ToTable.Rows.Count > 0 Then
                    ItemFound.Text = ""
                    ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."

                    Dim gvPageCount As Integer
                    gvPageCount = gvProductDisplay.PageCount
                    lblPageCounter.Text = gvPageCount.ToString
                    If pageCounter = 0 Then
                        gvProductDisplay.PageIndex = 0
                    ElseIf pageCounter >= gvPageCount Then
                        gvProductDisplay.PageIndex = gvPageCount
                    ElseIf pageCounter < gvPageCount Then
                        gvProductDisplay.PageIndex = pageCounter
                    End If
                    gvProductDisplay.DataSource = dt.DefaultView.ToTable
                    gvProductDisplay.DataBind()

                    If dt.Rows.Count = 1 Then
                        fillURL(dt.Rows(0).Item("Product_CategoryId").ToString)
                    Else
                        tdURL.InnerHtml = "&nbsp;"
                    End If

                    Dim count As Integer
                    For count = 0 To gvProductDisplay.Rows.Count - 1
                        Dim imgpath As String
                        imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dt.DefaultView.ToTable.Rows(count).Item("Product_Image").ToString())
                        KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                    Next

                    'If Request.QueryString("page") = Nothing Then
                    '    If dt.DefaultView.Table.Rows.Count <= 10 Then
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                    '    Else
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl & "&page=2")
                    '    End If
                    'Else
                    '    If dt.DefaultView.ToTable.Rows.Count <= 10 Then
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                    '    Else
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                    '    End If
                    '    If Request.QueryString("page") = 1 Then
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                    '    End If
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) - 1)
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) + 1)
                    'End If

                    ItemFound.Visible = True
                    imgbtnCompare.Visible = True
                    imglbtnAddtoWiseList.Visible = True
                    stirp.Visible = True
                    Label1.Visible = False
                    lnkInquiry.Visible = False
                    Label2.Visible = True
                End If
            ElseIf Request.QueryString("Value") = 2 Then
                If Request.QueryString("page") = Nothing Then
                    Session("Search2") = Nothing
                End If

                If IsNothing(Session("Search2")) Then
                    Dim con As New SqlConnection
                    con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                    dt1 = GetProductInformation("Product_Code", Request.QueryString("Key"))
                    Session("Search2") = dt1
                End If

                dt = CType(Session("Search2"), DataTable).DefaultView.ToTable
                If Request.QueryString("page") <> Nothing Then
                    Dim dtPage As New DataTable
                    dtPage = dt.Clone

                    Dim currentstart As Integer
                    Dim currentend As Integer
                    currentstart = ((CType(Request.QueryString("page"), Integer) - 1) * 10)
                    currentend = currentstart + 11
                    While currentstart <> currentend
                        Try
                            dtPage.Rows.Add(dt.Rows(currentstart).ItemArray)
                            currentstart = currentstart + 1
                        Catch ex As Exception
                            currentstart = currentend
                        End Try
                    End While

                    ItemFound.Text = ""
                    ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."

                    Dim gvPageCount As Integer
                    gvPageCount = gvProductDisplay.PageCount
                    lblPageCounter.Text = gvPageCount.ToString
                    If pageCounter = 0 Then
                        gvProductDisplay.PageIndex = 0
                    ElseIf pageCounter >= gvPageCount Then
                        gvProductDisplay.PageIndex = gvPageCount
                    ElseIf pageCounter < gvPageCount Then
                        gvProductDisplay.PageIndex = pageCounter
                    End If
                    gvProductDisplay.DataSource = dtPage.DefaultView.ToTable
                    gvProductDisplay.DataBind()

                    If dt.Rows.Count = 1 Then
                        fillURL(dt.Rows(0).Item("Product_CategoryId").ToString)
                    Else
                        tdURL.InnerHtml = "&nbsp;"
                    End If

                    Dim count As Integer
                    For count = 0 To gvProductDisplay.Rows.Count - 1
                        Dim imgpath As String
                        imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dtPage.Rows(count).Item("Product_Image").ToString())
                        KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                    Next

                    'If dt.DefaultView.ToTable.Rows.Count <= 10 Then
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                    'Else
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                    'End If

                    'If Request.QueryString("page") = 1 Then
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                    'End If

                    'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) - 1)
                    'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) + 1)
                    ItemFound.Visible = True
                    imgbtnCompare.Visible = True
                    imglbtnAddtoWiseList.Visible = True
                    stirp.Visible = True
                    Label1.Visible = False
                    lnkInquiry.Visible = False
                    Label2.Visible = True
                    Exit Sub
                End If

                If dt.DefaultView.ToTable.Rows.Count > 0 Then
                    ItemFound.Text = ""
                    ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."

                    Dim gvPageCount As Integer
                    gvPageCount = gvProductDisplay.PageCount
                    lblPageCounter.Text = gvPageCount.ToString
                    If pageCounter = 0 Then
                        gvProductDisplay.PageIndex = 0
                    ElseIf pageCounter >= gvPageCount Then
                        gvProductDisplay.PageIndex = gvPageCount
                    ElseIf pageCounter < gvPageCount Then
                        gvProductDisplay.PageIndex = pageCounter
                    End If
                    gvProductDisplay.DataSource = dt.DefaultView.ToTable
                    gvProductDisplay.DataBind()

                    If dt.Rows.Count = 1 Then
                        fillURL(dt.Rows(0).Item("Product_CategoryId").ToString)
                    Else
                        tdURL.InnerHtml = "&nbsp;"
                    End If
                    Dim count As Integer
                    For count = 0 To gvProductDisplay.Rows.Count - 1
                        Dim imgpath As String
                        imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dt.DefaultView.ToTable.Rows(count).Item("Product_Image").ToString())
                        KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                    Next
                    'If Request.QueryString("page") = Nothing Then
                    '    If dt.DefaultView.Table.Rows.Count <= 10 Then
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                    '    Else
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl & "&page=2")
                    '    End If
                    'Else
                    '    If dt.DefaultView.ToTable.Rows.Count <= 10 Then
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                    '    Else
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                    '    End If
                    '    If Request.QueryString("page") = 1 Then
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                    '    End If
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) - 1)
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) + 1)
                    'End If
                    ItemFound.Visible = True
                    imgbtnCompare.Visible = True
                    imglbtnAddtoWiseList.Visible = True
                    stirp.Visible = True
                    Label1.Visible = False
                    lnkInquiry.Visible = False
                    Label2.Visible = True
                End If
            ElseIf Request.QueryString("Value") = 3 Then
                If Request.QueryString("page") = Nothing Then
                    Session("Search3") = Nothing
                End If

                If IsNothing(Session("Search3")) Then
                    Dim con As New SqlConnection
                    con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                    dt1 = GetProductInformation("Brand_Name", Request.QueryString("Key"))
                    Session("Search3") = dt1
                End If

                dt = CType(Session("Search3"), DataTable).DefaultView.ToTable
                If Request.QueryString("page") <> Nothing Then
                    Dim dtPage As New DataTable
                    dtPage = dt.Clone

                    Dim currentstart As Integer
                    Dim currentend As Integer
                    currentstart = ((CType(Request.QueryString("page"), Integer) - 1) * 10)
                    currentend = currentstart + 11
                    While currentstart <> currentend
                        Try
                            dtPage.Rows.Add(dt.Rows(currentstart).ItemArray)
                            currentstart = currentstart + 1
                        Catch ex As Exception
                            currentstart = currentend
                        End Try
                    End While

                    ItemFound.Text = ""
                    ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."

                    Dim gvPageCount As Integer
                    gvPageCount = gvProductDisplay.PageCount
                    lblPageCounter.Text = gvPageCount.ToString
                    If pageCounter = 0 Then
                        gvProductDisplay.PageIndex = 0
                    ElseIf pageCounter >= gvPageCount Then
                        gvProductDisplay.PageIndex = gvPageCount
                    ElseIf pageCounter < gvPageCount Then
                        gvProductDisplay.PageIndex = pageCounter
                    End If
                    gvProductDisplay.DataSource = dtPage.DefaultView.ToTable
                    gvProductDisplay.DataBind()

                    If dt.Rows.Count = 1 Then
                        fillURL(dt.Rows(0).Item("Product_CategoryId").ToString)
                    Else
                        tdURL.InnerHtml = "&nbsp;"
                    End If

                    Dim count As Integer
                    For count = 0 To gvProductDisplay.Rows.Count - 1
                        Dim imgpath As String
                        imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dtPage.Rows(count).Item("Product_Image").ToString())
                        KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                    Next

                    'If dt.DefaultView.ToTable.Rows.Count <= 10 Then
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                    'Else
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                    'End If

                    'If Request.QueryString("page") = 1 Then
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                    'End If

                    'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) - 1)
                    'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) + 1)
                    ItemFound.Visible = True
                    imgbtnCompare.Visible = True
                    imglbtnAddtoWiseList.Visible = True
                    stirp.Visible = True
                    Label1.Visible = False
                    lnkInquiry.Visible = False
                    Label2.Visible = True
                    Exit Sub
                End If

                If dt.DefaultView.ToTable.Rows.Count > 0 Then
                    ItemFound.Text = ""
                    ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."

                    Dim gvPageCount As Integer
                    gvPageCount = gvProductDisplay.PageCount
                    lblPageCounter.Text = gvPageCount.ToString
                    If pageCounter = 0 Then
                        gvProductDisplay.PageIndex = 0
                    ElseIf pageCounter >= gvPageCount Then
                        gvProductDisplay.PageIndex = gvPageCount
                    ElseIf pageCounter < gvPageCount Then
                        gvProductDisplay.PageIndex = pageCounter
                    End If
                    gvProductDisplay.DataSource = dt.DefaultView.ToTable
                    gvProductDisplay.DataBind()

                    If dt.Rows.Count = 1 Then
                        fillURL(dt.Rows(0).Item("Product_CategoryId").ToString)
                    Else
                        tdURL.InnerHtml = "&nbsp;"
                    End If

                    Dim count As Integer
                    For count = 0 To gvProductDisplay.Rows.Count - 1
                        Dim imgpath As String
                        imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dt.DefaultView.ToTable.Rows(count).Item("Product_Image").ToString())
                        KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                    Next

                    'If Request.QueryString("page") = Nothing Then
                    '    If dt.DefaultView.Table.Rows.Count <= 10 Then
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                    '    Else
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl & "&page=2")
                    '    End If
                    'Else
                    '    If dt.DefaultView.ToTable.Rows.Count <= 10 Then
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                    '    Else
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                    '    End If
                    '    If Request.QueryString("page") = 1 Then
                    '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                    '    End If
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) - 1)
                    '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) + 1)
                    'End If
                    ItemFound.Visible = True
                    imgbtnCompare.Visible = True
                    imglbtnAddtoWiseList.Visible = True
                    stirp.Visible = True
                    Label1.Visible = False
                    lnkInquiry.Visible = False
                    Label2.Visible = True
                End If
            Else
                ItemFound.Visible = False
                Label2.Visible = False
                Label1.Visible = True
                Label4.Text = "<img alt='' src='" & Page.ResolveUrl("~/Images/javascripts.gif") & "'/>&nbsp; We Are registering products for this <b>" & Request.QueryString("Key") & "</b> search ! and will be up soon...<br /> For more details please Fill Up Your&nbsp; <strong>inquiry</strong>..."
            End If

            '------updated by Prachi - 18/08/2009 - to implement default search------
            If dt.Rows.Count = 0 Then
                If (Request.QueryString("key") <> Nothing) And (Request.QueryString("Value") = "0") Or (Request.QueryString("Value") = "1") Or (Request.QueryString("Value") = "2") Or (Request.QueryString("Value") = "3") Then
                    If Request.QueryString("page") = Nothing Then
                        Session("SearchDefault") = Nothing
                    End If

                    If IsNothing(Session("SearchDefault")) Then
                        Dim con As New SqlConnection
                        con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                        dt1 = GetProductInformation("Default", Request.QueryString("Key"))
                        Session("SearchDefault") = dt1
                    End If

                    dt = CType(Session("SearchDefault"), DataTable).DefaultView.ToTable
                    If Request.QueryString("page") <> Nothing Then
                        Dim dtPage As New DataTable
                        dtPage = dt.Clone
                        Dim currentstart As Integer
                        Dim currentend As Integer
                        currentstart = ((CType(Request.QueryString("page"), Integer) - 1) * 10)
                        currentend = currentstart + 11
                        While currentstart <> currentend
                            Try
                                dtPage.Rows.Add(dt.Rows(currentstart).ItemArray)
                                currentstart = currentstart + 1
                            Catch ex As Exception
                                currentstart = currentend
                            End Try
                        End While

                        ItemFound.Text = ""
                        ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."

                        Dim gvPageCount As Integer
                        gvPageCount = gvProductDisplay.PageCount
                        lblPageCounter.Text = gvPageCount.ToString
                        If pageCounter = 0 Then
                            gvProductDisplay.PageIndex = 0
                        ElseIf pageCounter >= gvPageCount Then
                            gvProductDisplay.PageIndex = gvPageCount
                        ElseIf pageCounter < gvPageCount Then
                            gvProductDisplay.PageIndex = pageCounter
                        End If
                        gvProductDisplay.DataSource = dtPage.DefaultView.ToTable
                        gvProductDisplay.DataBind()

                        If dt.Rows.Count = 1 Then
                            fillURL(dt.Rows(0).Item("Product_CategoryId").ToString)
                        Else
                            tdURL.InnerHtml = "&nbsp;"
                        End If

                        Dim count As Integer
                        For count = 0 To gvProductDisplay.Rows.Count - 1
                            Dim imgpath As String
                            imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dtPage.Rows(count).Item("Product_Image").ToString())
                            KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                        Next

                        'If dt.DefaultView.ToTable.Rows.Count <= 10 Then
                        '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                        '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                        'Else
                        '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                        '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                        'End If

                        'If Request.QueryString("page") = 1 Then
                        '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                        'End If

                        'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) - 1)
                        'CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) + 1)
                        ItemFound.Visible = True
                        imgbtnCompare.Visible = True
                        imglbtnAddtoWiseList.Visible = True
                        stirp.Visible = True
                        Label1.Visible = False
                        lnkInquiry.Visible = False
                        Label2.Visible = True
                        Exit Sub
                    End If
                    If dt.DefaultView.ToTable.Rows.Count > 0 Then
                        ItemFound.Text = ""
                        ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."

                        Dim gvPageCount As Integer
                        gvPageCount = gvProductDisplay.PageCount
                        lblPageCounter.Text = gvPageCount.ToString
                        If pageCounter = 0 Then
                            gvProductDisplay.PageIndex = 0
                        ElseIf pageCounter >= gvPageCount Then
                            gvProductDisplay.PageIndex = gvPageCount
                        ElseIf pageCounter < gvPageCount Then
                            gvProductDisplay.PageIndex = pageCounter
                        End If
                        gvProductDisplay.DataSource = dt.DefaultView.ToTable
                        gvProductDisplay.DataBind()

                        If dt.Rows.Count = 1 Then
                            fillURL(dt.Rows(0).Item("Product_CategoryId").ToString)
                        Else
                            tdURL.InnerHtml = "&nbsp;"
                        End If
                        Dim count As Integer
                        For count = 0 To gvProductDisplay.Rows.Count - 1
                            Dim imgpath As String
                            imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & dt.DefaultView.ToTable.Rows(count).Item("Product_Image").ToString())
                            KeepAspectRatioNew(CType(gvProductDisplay.Rows(count).Cells(0).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                        Next
                        'If Request.QueryString("page") = Nothing Then
                        '    If dt.DefaultView.Table.Rows.Count <= 10 Then
                        '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                        '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                        '    Else
                        '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                        '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl & "&page=2")
                        '    End If
                        'Else
                        '    If dt.DefaultView.ToTable.Rows.Count <= 10 Then
                        '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = False
                        '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                        '    Else
                        '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).Visible = True
                        '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
                        '    End If
                        '    If Request.QueryString("page") = 1 Then
                        '        CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = False
                        '    End If
                        '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) - 1)
                        '    CType(gvProductDisplay.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("&page")) & "&page=" & CType(Request.QueryString("page"), Integer) + 1)
                        'End If

                        ItemFound.Visible = True
                        imgbtnCompare.Visible = True
                        imglbtnAddtoWiseList.Visible = True
                        stirp.Visible = True
                        Label1.Visible = False
                        lnkInquiry.Visible = False
                        Label2.Visible = True
                    Else
                        Response.Redirect(Page.ResolveUrl("~/search/index/searchnotfound.aspx"))
                        ItemFound.Visible = False
                        imgbtnCompare.Visible = False
                        imglbtnAddtoWiseList.Visible = False
                        lbl1.Visible = False
                        txtCounter.Visible = False
                        lbl2.Visible = False
                        lblPageCounter.Visible = False
                        lbtnBack.Visible = False
                        lbtnNext.Visible = False
                        stirp.Visible = False
                        Label1.Visible = True
                        Label4.Text = "<img alt='' src='" & Page.ResolveUrl("~/Images/javascripts.gif") & "'/>&nbsp; We Are registering products for this <b>" & Request.QueryString("Key") & "</b> search ! and will be up soon...<br /> For more details please Fill Up Your&nbsp; <strong>inquiry</strong>..."
                        lnkInquiry.Visible = True
                        Label2.Visible = False
                        ds.Clear()
                    End If
                End If
            End If
            '------end update------

            gvProductDisplay.Visible = True
            ItemFound.Visible = True
        Catch ex As Exception
            ex.Message.ToString()
        End Try
    End Sub

    Protected Function createheaderlabel(ByVal prodid As String, ByVal bool As Boolean) As String
        Dim lblhead As String
        Dim parent As String
        If (bool) Then
            Dim con As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString"))
            Dim str As String = "SELECT     Category_Master.Category_Kid, Category_Master.Category_Name FROM         Product_Information INNER JOIN                     Category_Master ON Product_Information.Product_CategoryId = Category_Master.Category_Kid WHERE     Product_Information.Product_Kid = '" & prodid & "' AND (Category_Master.Category_IsDeleted = N'0')"
            Dim ds As New DataSet
            Dim sda As New SqlDataAdapter(str, con)
            sda.Fill(ds)
            parent = ds.Tables(0).Rows(0)(1).ToString
        Else
            parent = ReturnValue("Select Category_Name from Category_Master where Category_KId='" & RemoveLiterals(DecodeURL(Request.QueryString("Product_Id").ToString)) & "'")
        End If

        lblhead = parent & " >"
        While parent <> "Root Category"
            parent = ReturnValue("SELECT     Category_Master.Category_Name AS Expr2 FROM         Category_Master INNER JOIN                    Category_Master AS Category_Master_1 ON Category_Master.Category_Kid = Category_Master_1.Category_ParentId WHERE     (Category_Master.Category_IsDeleted = N'0') AND (Category_Master.Category_IsDeleted = N'0') AND Category_Master_1.Category_Name = '" & parent & "'")
            If parent = "" Then
                Exit While
            End If
            lblhead = parent & " >" & lblhead
        End While
        Session("HLabel") = lblhead
        Return lblhead
    End Function

    Protected Function ShopCartProcedure(ByVal StrMode As String, ByVal GridViewRow As GridViewRow) As Boolean
        Try
            Dim shopid As String = NewPrimaryKey(Me.Page)
            shopid = RemoveLiterals(shopid)
            Dim shopCode As String = Generate_Code("select count(*) from ShopCart where ShopCart_Code='", "SC")
            Dim con As New SqlConnection
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
            Dim cmd As New SqlCommand
            con.Open()
            Dim sqlcol As Data.SqlClient.SqlParameterCollection = cmd.Parameters
            sqlcol.Add("@ShopCart_Kid", SqlDbType.NVarChar, 10).Value = shopid.Trim
            sqlcol.Add("@ShopCart_Code", SqlDbType.NVarChar, 25).Value = shopCode.Trim
            sqlcol.Add("@ShopCart_ProductId", SqlDbType.NVarChar, 10).Value = CType(GridViewRow.FindControl("lnkprice"), LinkButton).CommandArgument
            sqlcol.Add("@ShopCart_BuyerUserId", SqlDbType.NVarChar, 25).Value = Session("BuyId")
            sqlcol.Add("@ShopCart_Quantity", SqlDbType.Int).Value = 1
            sqlcol.Add("@ShopCart_SpecialPrice", SqlDbType.Decimal, 18).Value = CType(GridViewRow.FindControl("lblprice"), Label).Text
            sqlcol.Add("@ShopCart_FinancialYearId", SqlDbType.NVarChar, 10).Value = "2007"
            sqlcol.Add("@ShopCart_CompanyId", SqlDbType.NVarChar, 10).Value = Session("companyId")
            sqlcol.Add("@ShopCart_UserId", SqlDbType.NVarChar, 10).Value = Session("UserId")
            sqlcol.Add("@FormName", SqlDbType.NVarChar, 50).Value = Me.Page.ToString
            sqlcol.Add("@Mode", SqlDbType.VarChar, 10).Value = StrMode.Trim
            ExecQuery("ShopCart_Proc", sqlcol).StartsWith("True")
            sqlcol = Nothing
            cmd = Nothing
            Return True
        Catch ex As Exception
            ex.Message.ToString()
        End Try
    End Function

    Protected Function WishListProcedure(ByVal StrMode As String, ByVal GridViewRow As GridViewRow) As Boolean
        Try
            Dim wishlistid As String = NewPrimaryKey(Me.Page)
            wishlistid = RemoveLiterals(wishlistid)
            Dim wishlistCode As String = Generate_Code("select count(*) from AddWishList where AddWishList_Code='", "WL")
            Dim con As New SqlConnection
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
            Dim cmd As New SqlCommand
            con.Open()
            Dim str As String = "select AddWishList_Code from AddWishList where AddWishList_ProductId='" & CType(GridViewRow.FindControl("lnkprice"), LinkButton).CommandArgument & "' and AddWishList_BuyerUserId='" & Session("BuyId") & "'"
            Dim da As New SqlDataAdapter(str, con)
            Dim ds As New DataSet
            da.Fill(ds)
            If ds.Tables(0).Rows.Count > 0 Then
                Return False
            Else
                Dim sqlcol As Data.SqlClient.SqlParameterCollection = cmd.Parameters
                sqlcol.Add("@AddWishList_Kid", SqlDbType.NVarChar, 10).Value = wishlistid.Trim
                sqlcol.Add("@AddWishList_Code", SqlDbType.NVarChar, 25).Value = wishlistCode.Trim
                sqlcol.Add("@AddWishList_ProductId", SqlDbType.NVarChar, 10).Value = CType(GridViewRow.FindControl("lnkprice"), LinkButton).CommandArgument
                sqlcol.Add("@AddWishList_BuyerUserId", SqlDbType.NVarChar, 25).Value = Session("BuyId")
                sqlcol.Add("@AddWishList_FinancialYearId", SqlDbType.NVarChar, 10).Value = "2007"
                sqlcol.Add("@AddWishList_CompanyId", SqlDbType.NVarChar, 10).Value = Session("companyId")
                sqlcol.Add("@AddWishList_UserId", SqlDbType.NVarChar, 10).Value = Session("UserId")
                sqlcol.Add("@FormName", SqlDbType.NVarChar, 50).Value = Me.Page.ToString
                sqlcol.Add("@Mode", SqlDbType.VarChar, 10).Value = StrMode.Trim
                ExecQuery("AddWishList_Proc", sqlcol).StartsWith("True")
                sqlcol = Nothing
                cmd = Nothing
                Return True
            End If
        Catch ex As Exception
            ex.Message.ToString()
        End Try
    End Function
#End Region
End Class
