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
    Dim ds As New DataSet
    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

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then

            If IsNothing(CatDistinct) Then
                GetCatDistinct()
            End If
            dtCategoryDistinct = CatDistinct

            If Request.QueryString("Product_KId") = Nothing Then
            Else

                productinfo()
                fillURL(CType(Session("Product"), DataTable).Rows(0)("Product_CategoryId").ToString)
                'Exit Sub
            End If

            If Request.QueryString("Brand_KId") = Nothing Then
                Session("brandid") = Nothing
            Else
                Session("brandid") = DecodeURL(Request.QueryString("Brand_KId"))
                BrandSelectedInfo()
                'Exit Sub
            End If
            If Request.QueryString("Product_HId") = Nothing Then
            Else
                Session("catid") = DecodeURL(Request.QueryString("Product_HId"))
                CategorySelectedInfoHead(DecodeURL(Request.QueryString("Product_HId")))
                fillURL(DecodeURL(Request.QueryString("Product_HId")))

                'Exit Sub
            End If
            If Request.QueryString("Product_Id") = Nothing Then
            Else
                Session("catid") = DecodeURL(Request.QueryString("Product_Id"))
                CategorySelectedInfo(DecodeURL(Request.QueryString("Product_Id")))
                fillURL(DecodeURL(Request.QueryString("Product_Id")))

                'Exit Sub
            End If

            If Request.QueryString("Product_DId") = Nothing Then

            Else
                CategorySelectedInfo(Request.QueryString("Product_DId"))
                fillURL(Request.QueryString("Product_DId"))
                'Exit Sub
            End If


            If Request.QueryString("key") = Nothing Then
            Else

                search_product()
                'Exit Sub
            End If


            For Each row As GridViewRow In gvProductDisplay.Rows
                Dim id As String = gvProductDisplay.DataKeys(row.RowIndex).Value
                Dim lnk As LinkButton = CType(row.Cells(0).FindControl("lnkprice"), LinkButton)
                CType(row.Cells(0).FindControl("lnkprice"), LinkButton).Attributes.Add("onclick", "return openform('" & EncodeURL(id) & "');")
            Next

            'tdURL.InnerHtml = Session("URL").ToString
            If Label1.Visible = True Then
                lnkInquiry.Attributes.Add("onclick", "return OpenInquery();")
            End If
            'Panel1.Attributes.Add("onmouseover", "pnlvisible(this);")
            'Panel1.Attributes.Add("onclick", "return pnlvisiblefalse(this);")
            'Panel1.Attributes.Add("onmouseout", "pnlvisiblefalse(this);")
            'Image1.Attributes.Add("onclick", "return enlargimgout();")
        End If


    End Sub
    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 = ""
        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)
        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")
                '                cmd = New SqlCommand("select ProductDisplay.*, Row_Number() over (order by (Product_Name)) as PIndex from ProductDisplay where Product_CategoryId='" & KID & "'", con)
                'cmd = New SqlCommand("select ProductDisplay.* from ProductDisplay where Product_CategoryId='" & KID & "' order by Product_Name", con)
                'cmd = New SqlCommand("SELECT     ProductDisplay.*  FROM ProductDisplay WHERE     (Product_CategoryId IN                          (SELECT     Category_Kid                FROM Category_Master                            WHERE      (Category_ParentId = N'" & RemoveLiterals(Session("catid").ToString) & "') AND (Category_IsDeleted = N'0')))", con)
                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')", con)
                    con.Open()
                    da = New SqlDataAdapter(cmd)
                    da.Fill(ds, "CategoryHead")
                    'If (ds.Tables("CategoryHead").Rows.Count = 0) Then
                    '    cmd = New SqlCommand("SELECT     ProductDisplay.*  FROM ProductDisplay WHERE     (Product_CategoryId IN                          (SELECT     Category_Kid                FROM Category_Master                            WHERE      (Category_ParentId = N'" & RemoveLiterals(Session("catid").ToString) & "') AND (Category_IsDeleted = N'0')))", con)
                    '    'con.Open()
                    '    da = New SqlDataAdapter(cmd)
                    '    da.Fill(ds, "CategoryHead")
                    'End If
                    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 start As Integer
                '''start = CType(dt.Rows(0).Item("Pindex").ToString(), Integer)
                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

                'For i = 0 To 10

                'Next
                'For currentstart To currentend

                'Next

                'dt.DefaultView.ToTable.Clear()
                'dt = dtPage
                '''dt.DefaultView.RowFilter = "PIndex >= " & currentstart & " And PIndex <=" & currentend

                ItemFound.Text = ""

                strProductName = ReturnValue("SELECT     Category_Name         FROM Category_Master  WHERE     Category_Kid ='" & KID & "'")
                ItemFound.Text = CType(Session("CategoryHead"), DataTable).Rows.Count & " Item(s) Found in  " & strProductName & " Category."


                gvProductDisplay.DataSource = dtPage.DefaultView.ToTable
                'ds.Tables("Product_Mast")
                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
                btnCompare.Visible = True
                lbtnAddtoWiseList.Visible = True
                ' lbtnAddtocart.Visible = True
                Label1.Visible = False
                Label3.Visible = True
                lnkInquiry.Visible = False
                Label2.Visible = True
                Exit Sub
            End If

            If dt.DefaultView.ToTable.Rows.Count > 0 Then

                ItemFound.Text = ""

                strProductName = ReturnValue("SELECT     Category_Name         FROM Category_Master  WHERE     Category_Kid ='" & KID & "'")
                ItemFound.Text = CType(Session("CategoryHead"), DataTable).Rows.Count & " Item(s) Found in  " & strProductName & " Category."

                gvProductDisplay.DataSource = dt.DefaultView.ToTable
                'ds.Tables("Product_Mast")
                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





                'lblHead.Text = createheaderlabel("", False)
                'lblHead.Text = Session("HLabel")
                ItemFound.Visible = True
                btnCompare.Visible = True
                lbtnAddtoWiseList.Visible = True
                'lbtnAddtocart.Visible = True
                Label1.Visible = False
                lnkInquiry.Visible = False
                Label2.Visible = True
                Label3.Visible = True
                ' ''Session("backcatid") = Nothing

            Else
                strProductName = ReturnValue("SELECT     Category_Name         FROM Category_Master  WHERE     Category_Kid ='" & KID & "'")
                'lblHead.Visible = True
                'lblHead.Text = createheaderlabel("", False)
                ItemFound.Visible = False
                btnCompare.Visible = False
                lbtnAddtoWiseList.Visible = False
                'lbtnAddtocart.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
                Label3.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)
        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")
                '                cmd = New SqlCommand("select ProductDisplay.*, Row_Number() over (order by (Product_Name)) as PIndex from ProductDisplay where Product_CategoryId='" & KID & "'", con)
                cmd = New SqlCommand("select ProductDisplay.* from ProductDisplay where Product_CategoryId='" & KID & "' order by Product_Name", con)

                con.Open()
                da = New SqlDataAdapter(cmd)
                da.Fill(ds, "Categroy")
                Session("Category") = ds.Tables("Categroy")
            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 start As Integer
                '''start = CType(dt.Rows(0).Item("Pindex").ToString(), Integer)
                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

                'For i = 0 To 10

                'Next
                'For currentstart To currentend

                'Next

                'dt.DefaultView.ToTable.Clear()
                'dt = dtPage
                '''dt.DefaultView.RowFilter = "PIndex >= " & currentstart & " And PIndex <=" & currentend

                ItemFound.Text = ""

                strProductName = ReturnValue("SELECT     Category_Name         FROM Category_Master  WHERE     Category_Kid ='" & KID & "'")
                ItemFound.Text = CType(Session("Category"), DataTable).Rows.Count & " Item(s) Found in  " & strProductName & " Category."


                gvProductDisplay.DataSource = dtPage.DefaultView.ToTable
                'ds.Tables("Product_Mast")
                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
                btnCompare.Visible = True
                lbtnAddtoWiseList.Visible = True
                ' lbtnAddtocart.Visible = True
                Label1.Visible = False
                Label3.Visible = True
                lnkInquiry.Visible = False
                Label2.Visible = True
                Exit Sub
            End If

            If dt.DefaultView.ToTable.Rows.Count > 0 Then

                ItemFound.Text = ""

                strProductName = ReturnValue("SELECT     Category_Name         FROM Category_Master  WHERE     Category_Kid ='" & KID & "'")
                ItemFound.Text = CType(Session("Category"), DataTable).Rows.Count & " Item(s) Found in  " & strProductName & " Category."

                gvProductDisplay.DataSource = dt.DefaultView.ToTable
                'ds.Tables("Product_Mast")
                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





                'lblHead.Text = createheaderlabel("", False)
                'lblHead.Text = Session("HLabel")
                ItemFound.Visible = True
                btnCompare.Visible = True
                lbtnAddtoWiseList.Visible = True
                'lbtnAddtocart.Visible = True
                Label1.Visible = False
                lnkInquiry.Visible = False
                Label2.Visible = True
                Label3.Visible = True
                ' ''Session("backcatid") = Nothing

            Else
                strProductName = ReturnValue("SELECT     Category_Name         FROM Category_Master  WHERE     Category_Kid ='" & KID & "'")
                'lblHead.Visible = True
                'lblHead.Text = createheaderlabel("", False)
                ItemFound.Visible = False
                btnCompare.Visible = False
                lbtnAddtoWiseList.Visible = False
                'lbtnAddtocart.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
                Label3.Visible = False


                ds.Clear()
            End If
            con.Close()







        Catch ex As Exception
            ex.Message.ToString()
        End Try
    End Sub
    Private Sub productinfo()
        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.*, Row_Number() over (order by (Product_Code)) as PIndex from ProductDisplay where (ProductDisplay.Product_Name LIKE '%" & Product_Name.Trim.Replace("'", "") & "%')", con)
                cmd = New SqlCommand("select ProductDisplay.* from ProductDisplay where (ProductDisplay.Product_Name LIKE '%" & Product_Name.Trim.Replace("'", "") & "%') order by Product_Name", 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 start As Integer
                '''start = CType(dt.Rows(0).Item("Pindex").ToString(), Integer)
                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

                'For i = 0 To 10

                'Next
                'For currentstart To currentend

                'Next

                'dt.DefaultView.ToTable.Clear()
                'dt = dtPage
                '''dt.DefaultView.RowFilter = "PIndex >= " & currentstart & " And PIndex <=" & currentend

                ItemFound.Text = ""
                ItemFound.Text = dt.Rows.Count & " Item(s) Found for  " & Request.QueryString("Product_KId").Replace("-", " ") & "."


                gvProductDisplay.DataSource = dtPage.DefaultView.ToTable
                'ds.Tables("Product_Mast")
                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
                btnCompare.Visible = True
                lbtnAddtoWiseList.Visible = True
                ' lbtnAddtocart.Visible = True
                Label1.Visible = False
                Label3.Visible = True
                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("-", " ") & "."
                gvProductDisplay.DataSource = dt.DefaultView.ToTable
                'ds.Tables("Product_Mast")
                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



                'lblHead.Text = createheaderlabel(dt.DefaultView.ToTable.Rows(0).Item(0).ToString, True)
                'lblHead.Text = Session("HLabel")
                ItemFound.Visible = True
                btnCompare.Visible = True
                lbtnAddtoWiseList.Visible = True
                ' lbtnAddtocart.Visible = True
                Label1.Visible = False
                Label3.Visible = True
                lnkInquiry.Visible = False
                Label2.Visible = True
                ' ''Session("backcatid") = Nothing

            Else

                ItemFound.Visible = False
                btnCompare.Visible = False
                lbtnAddtoWiseList.Visible = False
                ' lbtnAddtocart.Visible = False
                Label1.Visible = True
                Label3.Visible = False
                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()
        Try
            'BrandId = Request.QueryString("Brand_KId")
            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")
                '''                cmd = New SqlCommand("select ProductDisplay.*, Row_Number() over (order by (Product_Name)) as PIndex from ProductDisplay where (ProductDisplay.Product_BrandId='" & DecodeURL(Request.QueryString("Brand_KId")) & "')", con)
                cmd = New SqlCommand("select ProductDisplay.* from ProductDisplay where (ProductDisplay.Product_BrandId='" & DecodeURL(Request.QueryString("Brand_KId")) & "') order by Product_Name", con)
                'cmd = New SqlCommand("SELECT  Product_Kid, Product_Code, Product_Name, Product_ModelNo, Product_AtcoPrice, Brand_Name, Product_CategoryId, Product_Image, Product_BrandId, Product_Approved, Substring(isnull(Product_Information.Product_Description,'N.A.') , 1 ,100)+''+Substring(isnull(Product_Information.Product_Description,'N.A.') , 101 ,CHARINDEX('.', Substring(isnull(Product_Information.Product_Description,'N.A.') , 101,400))) as Product_Description from Product_Information where Product_Approved='Y'  and  Product_name like '%" & prodid.Replace("'", "") & "'", con)
                ' Dim str As String = "SELECT * from Product_Information where Product_Approved='Y' and  Product_name=" & prodid
                con.Open()
                da = New SqlDataAdapter(cmd)
                da.Fill(ds, "Brand")
                Session("Brand") = ds.Tables("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 start As Integer
                '''start = CType(dt.Rows(0).Item("Pindex").ToString(), Integer)
                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

                'For i = 0 To 10

                'Next
                'For currentstart To currentend

                'Next

                'dt.DefaultView.ToTable.Clear()
                'dt = dtPage
                '''dt.DefaultView.RowFilter = "PIndex >= " & currentstart & " And PIndex <=" & currentend

                ItemFound.Text = ""

                brandname = ReturnValue("SELECT    Brand_Name    FROM Brand_Master WHERE     Brand_Kid ='" & DecodeURL(Request.QueryString("Brand_KId")) & "'")
                ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & brandname & " Brand."


                gvProductDisplay.DataSource = dtPage.DefaultView.ToTable
                'ds.Tables("Product_Mast")
                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
                btnCompare.Visible = True
                lbtnAddtoWiseList.Visible = True
                'lbtnAddtocart.Visible = True
                Label1.Visible = False
                Label3.Visible = True
                lnkInquiry.Visible = False
                Label2.Visible = True
                Exit Sub
            End If

            If dt.DefaultView.ToTable.Rows.Count > 0 Then

                ItemFound.Text = ""

                brandname = ReturnValue("SELECT    Brand_Name    FROM Brand_Master WHERE     Brand_Kid ='" & DecodeURL(Request.QueryString("Brand_KId")) & "'")
                ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & brandname & " Brand."

                gvProductDisplay.DataSource = dt.DefaultView.ToTable
                'ds.Tables("Product_Mast")
                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




                'lblHead.Text = createheaderlabel(dt.DefaultView.ToTable.Rows(0).Item(0).ToString, True)
                'lblHead.Text = Session("HLabel")
                ItemFound.Visible = True
                btnCompare.Visible = True
                lbtnAddtoWiseList.Visible = True
                ' lbtnAddtocart.Visible = True
                Label1.Visible = False
                lnkInquiry.Visible = False
                Label2.Visible = True
                Label3.Visible = True
                ' ''Session("backcatid") = Nothing

            Else
                brandname = ReturnValue("SELECT    Brand_Name    FROM Brand_Master WHERE     Brand_Kid ='" & DecodeURL(Request.QueryString("Brand_KId")) & "'")
                'lblHead.Visible = True
                'lblHead.Text = createheaderlabel(dt.DefaultView.ToTable.Rows(0).Item(0).ToString, True)
                ItemFound.Visible = False
                btnCompare.Visible = False
                lbtnAddtoWiseList.Visible = False
                'lbtnAddtocart.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
                Label3.Visible = False


                ds.Clear()
            End If
            con.Close()




        Catch ex As Exception
            ex.Message.ToString()
        End Try
    End Sub
    Private Sub search_product()
        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
                    con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                    'strr = "select ProductDisplay.*, Row_Number() over (order by (Product_Name)) as PIndex 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") & "'"
                    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") & "%' order by Product_Name"
                    cmd = New SqlCommand(strr, con)
                    Dim da As New SqlDataAdapter(cmd)
                    da.Fill(ds, "Info")
                    Session("Search0") = ds.Tables("Info")
                End If
                Dim dt As DataTable
                dt = CType(Session("Search0"), DataTable).DefaultView.ToTable

                If Request.QueryString("page") <> Nothing Then


                    Dim dtPage As New DataTable
                    dtPage = dt.Clone
                    '''Dim start As Integer
                    '''start = CType(dt.Rows(0).Item("Pindex").ToString(), Integer)
                    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

                    'For i = 0 To 10

                    'Next
                    'For currentstart To currentend

                    'Next

                    'dt.DefaultView.ToTable.Clear()
                    'dt = dtPage
                    '''dt.DefaultView.RowFilter = "PIndex >= " & currentstart & " And PIndex <=" & currentend

                    ItemFound.Text = ""
                    'Dim brandname As String = ReturnValue("SELECT    Brand_Name    FROM Brand_Master WHERE     Brand_Kid ='" & BrandId & "'")
                    ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."


                    gvProductDisplay.DataSource = dtPage.DefaultView.ToTable
                    'ds.Tables("Product_Mast")
                    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 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
                    btnCompare.Visible = True
                    lbtnAddtoWiseList.Visible = True
                    ' lbtnAddtocart.Visible = True
                    Label1.Visible = False
                    Label3.Visible = True
                    lnkInquiry.Visible = False
                    Label2.Visible = True
                    Exit Sub
                End If
                If dt.DefaultView.ToTable.Rows.Count > 0 Then
                    ItemFound.Text = ""
                    'Dim brandname As String = ReturnValue("SELECT    Brand_Name    FROM Brand_Master WHERE     Brand_Kid ='" & BrandId & "'")
                    ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."

                    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

                    lblHead.Text = createheaderlabel(dt.DefaultView.ToTable.Rows(0).Item(0).ToString, True)
                    'lblHead.Text = Session("HLabel")
                    ItemFound.Visible = True
                    btnCompare.Visible = True
                    lbtnAddtoWiseList.Visible = True
                    ' lbtnAddtocart.Visible = True
                    Label1.Visible = False
                    lnkInquiry.Visible = False
                    Label2.Visible = True
                    Label3.Visible = True
                    ' ''Session("backcatid") = Nothing

                Else
                    ItemFound.Visible = False
                    btnCompare.Visible = False
                    lbtnAddtoWiseList.Visible = False
                    'lbtnAddtocart.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
                    Label3.Visible = False
                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")
                    '                    strr = "select ProductDisplay.*, Row_Number() over (order by (Product_Name)) as PIndex from ProductDisplay where Product_ModelNo Like '%" & Request.QueryString("Key") & "%'"
                    strr = "select ProductDisplay.* from ProductDisplay where Product_ModelNo Like '%" & Request.QueryString("Key") & "%' order by Product_Name"
                    cmd = New SqlCommand(strr, con)
                    Dim da As New SqlDataAdapter(cmd)
                    da.Fill(ds, "Info")
                    Session("Search1") = ds.Tables("Info")
                End If
                Dim dt As DataTable
                dt = CType(Session("Search1"), DataTable).DefaultView.ToTable

                If Request.QueryString("page") <> Nothing Then


                    Dim dtPage As New DataTable
                    dtPage = dt.Clone
                    '''Dim start As Integer
                    '''start = CType(dt.Rows(0).Item("Pindex").ToString(), Integer)
                    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

                    'For i = 0 To 10

                    'Next
                    'For currentstart To currentend

                    'Next

                    'dt.DefaultView.ToTable.Clear()
                    'dt = dtPage
                    '''dt.DefaultView.RowFilter = "PIndex >= " & currentstart & " And PIndex <=" & currentend

                    ItemFound.Text = ""
                    'Dim brandname As String = ReturnValue("SELECT    Brand_Name    FROM Brand_Master WHERE     Brand_Kid ='" & BrandId & "'")
                    ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."

                    gvProductDisplay.DataSource = dtPage.DefaultView.ToTable
                    'ds.Tables("Product_Mast")
                    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 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
                    btnCompare.Visible = True
                    lbtnAddtoWiseList.Visible = True
                    ' lbtnAddtocart.Visible = True
                    Label1.Visible = False
                    lnkInquiry.Visible = False
                    Label2.Visible = True
                    Label3.Visible = True
                    Exit Sub
                End If
                If dt.DefaultView.ToTable.Rows.Count > 0 Then
                    ItemFound.Text = ""
                    'Dim brandname As String = ReturnValue("SELECT    Brand_Name    FROM Brand_Master WHERE     Brand_Kid ='" & BrandId & "'")
                    ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."

                    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

                    lblHead.Text = createheaderlabel(dt.DefaultView.ToTable.Rows(0).Item(0).ToString, True)
                    'lblHead.Text = Session("HLabel")
                    ItemFound.Visible = True
                    btnCompare.Visible = True
                    lbtnAddtoWiseList.Visible = True
                    'lbtnAddtocart.Visible = True
                    Label1.Visible = False
                    lnkInquiry.Visible = False
                    Label2.Visible = True
                    Label3.Visible = True
                    ' ''Session("backcatid") = Nothing

                Else
                    ItemFound.Visible = False
                    btnCompare.Visible = False
                    lbtnAddtoWiseList.Visible = False
                    'lbtnAddtocart.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
                    Label3.Visible = False
                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")
                    'strr = "select ProductDisplay.*, Row_Number() over (order by (Product_Name)) as PIndex from ProductDisplay where Product_Code Like '%" & Request.QueryString("Key") & "%'"
                    strr = "select ProductDisplay.* from ProductDisplay where Product_Code Like '" & Request.QueryString("Key") & "%' order by Product_Name"
                    cmd = New SqlCommand(strr, con)
                    Dim da As New SqlDataAdapter(cmd)
                    da.Fill(ds, "Info")
                    Session("Search2") = ds.Tables("Info")
                End If
                Dim dt As DataTable
                dt = CType(Session("Search2"), DataTable).DefaultView.ToTable

                If Request.QueryString("page") <> Nothing Then


                    Dim dtPage As New DataTable
                    dtPage = dt.Clone
                    '''Dim start As Integer
                    '''start = CType(dt.Rows(0).Item("Pindex").ToString(), Integer)
                    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

                    'For i = 0 To 10

                    'Next
                    'For currentstart To currentend

                    'Next

                    'dt.DefaultView.ToTable.Clear()
                    'dt = dtPage
                    '''dt.DefaultView.RowFilter = "PIndex >= " & currentstart & " And PIndex <=" & currentend

                    ItemFound.Text = ""
                    'Dim brandname As String = ReturnValue("SELECT    Brand_Name    FROM Brand_Master WHERE     Brand_Kid ='" & BrandId & "'")
                    ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."

                    gvProductDisplay.DataSource = dtPage.DefaultView.ToTable
                    'ds.Tables("Product_Mast")
                    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 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
                    btnCompare.Visible = True
                    lbtnAddtoWiseList.Visible = True
                  '  lbtnAddtocart.Visible = True
                    Label1.Visible = False
                    lnkInquiry.Visible = False
                    Label2.Visible = True
                    Label3.Visible = True
                    Exit Sub
                End If
                If dt.DefaultView.ToTable.Rows.Count > 0 Then
                    ItemFound.Text = ""
                    'Dim brandname As String = ReturnValue("SELECT    Brand_Name    FROM Brand_Master WHERE     Brand_Kid ='" & BrandId & "'")
                    ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."

                    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

                    lblHead.Text = createheaderlabel(dt.DefaultView.ToTable.Rows(0).Item(0).ToString, True)
                    'lblHead.Text = Session("HLabel")
                    ItemFound.Visible = True
                    btnCompare.Visible = True
                    lbtnAddtoWiseList.Visible = True
                    '   lbtnAddtocart.Visible = True
                    Label1.Visible = False
                    lnkInquiry.Visible = False
                    Label2.Visible = True
                    Label3.Visible = True
                    ' ''Session("backcatid") = Nothing

                Else
                    ItemFound.Visible = False
                    btnCompare.Visible = False
                    lbtnAddtoWiseList.Visible = False
                    '   lbtnAddtocart.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
                    Label3.Visible = False
                    ds.Clear()
                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")
                    'strr = "select ProductDisplay.*, Row_Number() over (order by (Product_Name)) as PIndex from ProductDisplay where Brand_Name Like '%" & Request.QueryString("Key") & "%'"
                    strr = "select ProductDisplay.* from ProductDisplay where Brand_Name Like '" & Request.QueryString("Key") & "%' order by Product_Name"
                    cmd = New SqlCommand(strr, con)
                    Dim da As New SqlDataAdapter(cmd)
                    da.Fill(ds, "Info")
                    Session("Search3") = ds.Tables("Info")
                End If
                Dim dt As DataTable
                dt = CType(Session("Search3"), DataTable).DefaultView.ToTable
                If Request.QueryString("page") <> Nothing Then


                    Dim dtPage As New DataTable
                    dtPage = dt.Clone
                    '''Dim start As Integer
                    '''start = CType(dt.Rows(0).Item("Pindex").ToString(), Integer)
                    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

                    'For i = 0 To 10

                    'Next
                    'For currentstart To currentend

                    'Next

                    'dt.DefaultView.ToTable.Clear()
                    'dt = dtPage
                    '''dt.DefaultView.RowFilter = "PIndex >= " & currentstart & " And PIndex <=" & currentend

                    ItemFound.Text = ""
                    'Dim brandname As String = ReturnValue("SELECT    Brand_Name    FROM Brand_Master WHERE     Brand_Kid ='" & BrandId & "'")
                    ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."


                    gvProductDisplay.DataSource = dtPage.DefaultView.ToTable
                    'ds.Tables("Product_Mast")
                    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 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
                    btnCompare.Visible = True
                    lbtnAddtoWiseList.Visible = True
                    '   lbtnAddtocart.Visible = True
                    Label1.Visible = False
                    lnkInquiry.Visible = False
                    Label2.Visible = True
                    Label3.Visible = True
                    Exit Sub
                End If
                If dt.DefaultView.ToTable.Rows.Count > 0 Then
                    ItemFound.Text = ""
                    'Dim brandname As String = ReturnValue("SELECT    Brand_Name    FROM Brand_Master WHERE     Brand_Kid ='" & BrandId & "'")
                    ItemFound.Text = dt.Rows.Count & " Item(s) Found in " & Request.QueryString("Key") & " Search."

                    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

                    lblHead.Text = createheaderlabel(dt.DefaultView.ToTable.Rows(0).Item(0).ToString, True)
                    'lblHead.Text = Session("HLabel")
                    ItemFound.Visible = True
                    btnCompare.Visible = True
                    lbtnAddtoWiseList.Visible = True
                    'lbtnAddtocart.Visible = True
                    Label1.Visible = False
                    lnkInquiry.Visible = False
                    Label2.Visible = True
                    Label3.Visible = True
                    ' ''Session("backcatid") = Nothing

                Else
                    ItemFound.Visible = False
                    btnCompare.Visible = False
                    lbtnAddtoWiseList.Visible = False
                    '  lbtnAddtocart.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
                    Label3.Visible = False
                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

            gvProductDisplay.Visible = True
            'btnCompare.Visible = True
            'lbtnAddtoWiseList.Visible = True
            'lbtnAddtocart.Visible = True
            ItemFound.Visible = True

        Catch ex As Exception
            ex.Message.ToString()
        End Try
    End Sub
    Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        Dim d As New ImageButton()
        d = CType(sender, ImageButton)
        Dim dd As String = d.CommandArgument
        createheaderlabel(dd, True)
        Session("backcatid") = Nothing   '' Session Form ProductDetail Control by Kalpesh Patel

        Response.Redirect("SearchProductDetails.aspx?ProductCode=" & dd)



    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
        If Not CatSearch = Nothing Then
            'CategorySelectedInfo()
        End If
        If Not prodid = Nothing Then
            productinfo()
        End If
        If Not BrandId = Nothing Then
            BrandSelectedInfo()
        End If
        If Not searchopt = Nothing Then
            search_product()
        End If
        If Not catid = Nothing Then
            'CategorySelectedInfo()
        End If
    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 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
        btnCompare.Visible = True
        lbtnAddtoWiseList.Visible = True
        'lbtnAddtocart.Visible = True
        ItemFound.Visible = True
        Label2.Visible = True
        Label1.Visible = False


    End Sub
    Protected Sub btnCompare_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        gvProductDisplay.Visible = True
        btnCompare.Visible = True
        ItemFound.Visible = True
        lbtnAddtoWiseList.Visible = True
        '  lbtnAddtocart.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 lbtnAddtocart_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtnAddtocart.Click
    '    Try

    '        gvProductDisplay.Visible = True
    '        btnCompare.Visible = True
    '        ItemFound.Visible = True
    '        lbtnAddtoWiseList.Visible = True
    '        lbtnAddtocart.Visible = True
    '        '    Dim hashData As New Hashtable
    '        Dim gvRow As GridViewRow
    '        ' Dim chk As New CheckBox
    '        '  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") = hashData
    '        Dim shoptabel As New DataTable
    '        shoptabel.Columns.Add("ProductId")
    '        If Session("BuyId") = Nothing Then

    '            For Each gvRow In gvProductDisplay.Rows
    '                If CType(gvRow.FindControl("CheckBox2"), CheckBox).Checked = True Then
    '                    Dim shrow As DataRow = shoptabel.NewRow
    '                    shrow("ProductId") = gvProductDisplay.DataKeys(gvRow.RowIndex).Value
    '                    'shrow("ProductId") = CType(gvRow.FindControl("Imgbtn"), Image).CommandArgument
    '                    shoptabel.Rows.Add(shrow)
    '                End If
    '            Next
    '            If shoptabel.Rows.Count < 1 Then
    '                ItemMinMax.Visible = True
    '                ItemMinMax.Text = "<br/><img alt='' src='" & Page.ResolveUrl("~/Images/javascripts.gif") & "'/>Please Select Minimum One  Product."
    '                Session("ShopTabel") = Nothing
    '                Exit Sub

    '            Else
    '                Session("ShopTabel") = Nothing
    '                Session("Checkstatus") = "ShopCart"
    '                Session("ShopTabel") = shoptabel
    '                ItemMinMax.Text = ""
    '                ItemMinMax.Visible = False
    '                Response.Redirect("~/Buyer/BuyerLogin.aspx")
    '            End If

    '        Else
    '            For Each gvRow In gvProductDisplay.Rows
    '                If CType(gvRow.FindControl("CheckBox2"), CheckBox).Checked = True Then
    '                    If ShopCartProcedure("Insert", gvRow) = True Then
    '                        total = total + 1
    '                    End If
    '                End If
    '            Next
    '            Response.Redirect("~/Buyer/ShopCart.aspx")
    '        End If

    '    Catch ex As Exception

    '    End Try
    '    'End If
    'End Sub
    Protected Sub lbtnAddtoWiseList_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtnAddtoWiseList.Click
        Try

            gvProductDisplay.Visible = True
            btnCompare.Visible = True
            ItemFound.Visible = True
            lbtnAddtoWiseList.Visible = True
            'lbtnAddtocart.Visible = True
            Dim gvRow As GridViewRow

            '   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") = hashData
            'Session("ItemMaxMin") = hashData

            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
                        'wsrow("ProductId") = CType(gvRow.FindControl("Imgbtn"), ImageButton).CommandArgument
                        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("~/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

        End Try
    End Sub
    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                        'Define connection variable for connecting to SQL-Server
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")    'Read the ConnectionString from web.config File
            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                        'Define connection variable for connecting to SQL-Server
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")    'Read the ConnectionString from web.config File
            Dim cmd As New SqlCommand
            con.Open()
            'Dim str As String = "select AddWishList_Code from AddWishList where AddWishList_ProductId='" & CType(GridViewRow.FindControl("Imgbtn"), ImageButton).CommandArgument & "' and AddWishList_BuyerUserId='" & Session("BuyId") & "'"
            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
    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)

            CType(e.Row.Cells(0).FindControl("imgbtn"), Image).Attributes.Add("onmouseover", "enlargimg(this,'" & Image1.ClientID.ToString & "');")
            CType(e.Row.Cells(0).FindControl("imgbtn"), Image).Attributes.Add("onmouseout", "enlargimgout(this,'" & Image1.ClientID.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='#B7CBE3'")
                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(230, 239, 246)
                e.Row.BackColor = c
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#B7CBE3'")
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#E6EFF6'")
            End If



        End If
    End Sub
End Class

