Imports System.Data
Imports System.Data.SqlClient
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Partial Class UserControl_CategorySearch
    Inherits System.Web.UI.UserControl
    Dim dtCategoryDistinct As DataTable
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Try
            If Not IsPostBack Then

                If IsNothing(Session("CategoryDistinct")) Then

                    If IsNothing(CatDistinct) Then
                        GetCatDistinct()
                    End If
                    Session("CategoryDistinct") = CatDistinct
                    'Session("CategoryDistinct") = ReturnDataTable("Select * from CategoryDistinct")
                    dtCategoryDistinct = CType(Session("CategoryDistinct"), DataTable)
                Else
                    dtCategoryDistinct = CType(Session("CategoryDistinct"), DataTable)
                End If


                If Request.QueryString("MainCat") <> Nothing Then
                    Session("MainCat1") = Nothing
                    Session("SubCat1") = Nothing
                    'Session("SubCat2") = Nothing
                    'Session("MainCat1") = Nothing
                    'Session("SubCat11") = Nothing
                    Dim strCatID As String
                    strCatID = RemoveLiterals(DecodeURL(Request.QueryString("MainCat").ToString))
                    Session("MainCat") = RemoveLiterals(DecodeURL(Request.QueryString("MainCat").ToString))
                    fillURL(RemoveLiterals(DecodeURL(Request.QueryString("MainCat"))))
                    fillMainCat(RemoveLiterals(Session("MainCat")))
                    ' ''Session("URL1") = "<a href='" & Request.RawUrl & "'>" & ReturnValue("Select Category_Name from Category_Distinct where Category_KId='" & RemoveLiterals(Session("MainCat")) & "'") & "</a> > "
                    ' ''td.InnerHtml = ""
                    ' ''td.InnerHtml = Session("URL1").ToString
                    ' ''Session("URL") = td.InnerHtml.ToString
                    Session("Title1") = ReturnValue("Select Category_Name from Category_Distinct where Category_KId='" & RemoveLiterals(Session("MainCat")) & "'") & " - Atcomaart Industrial Supply"
                    Page.Title = StrConv(Session("Title1").ToString, VbStrConv.ProperCase)
                    Session("Title") = Page.Title
                    'TextBox1.Text = "<a href='" & Request.RawUrl & "'>" & ReturnValue("Select Category_Name from Category_Distinct where Category_KId='" & RemoveLiterals(Session("MainCat")) & "'") & "</a> > "
                    FillMeta(RemoveLiterals(Session("MainCat")))



                End If

                If Request.QueryString("MainCat1") <> Nothing Then
                    Session("MainCat1") = Nothing
                    Session("SubCat1") = Nothing
                    Dim strCatID As String
                    strCatID = RemoveLiterals(DecodeURL(Request.QueryString("MainCat1").ToString))
                    Session("MainCat1") = RemoveLiterals(DecodeURL(Request.QueryString("MainCat1").ToString))
                    fillURL(RemoveLiterals(DecodeURL(Request.QueryString("MainCat1"))))
                    fillsubCat2(RemoveLiterals(Session("SubCat2")))
                    fillMainCat1(RemoveLiterals(Session("MainCat1")))
                    ' ''Session("URL4") = "<a href='" & Request.RawUrl & "'>" & ReturnValue("Select Category_Name from CategoryDistinct where Category_KId='" & RemoveLiterals(Session("MainCat1")) & "'") & "</a> > "
                    ' ''td.InnerHtml = ""
                    ' ''td.InnerHtml = Session("URL1").ToString & Session("URL2").ToString & Session("URL3").ToString & Session("URL4").ToString
                    ' ''Session("URL") = td.InnerHtml.ToString
                    Session("Title4") = ReturnValue("Select Category_Name from CategoryDistinct where Category_KId='" & RemoveLiterals(Session("MainCat1")) & "'")
                    Page.Title = StrConv(Session("Title4").ToString, VbStrConv.ProperCase) & ", " & StrConv(Session("Title3").ToString, VbStrConv.ProperCase) & ", " & StrConv(Session("Title2").ToString, VbStrConv.ProperCase) & ", " & StrConv(Session("Title1").ToString, VbStrConv.ProperCase)
                    Session("Title") = Page.Title
                    FillMeta(RemoveLiterals(Session("MainCat1")))



                    'TextBox1.Text = "<a href='" & Request.RawUrl & "'>" & ReturnValue("Select Category_Name from Category_Distinct where Category_KId='" & RemoveLiterals(Session("MainCat")) & "'") & "</a> > "
                End If

                If Request.QueryString("SubCat1") <> Nothing Then
                    Session("MainCat1") = Nothing
                    Session("SubCat1") = RemoveLiterals(DecodeURL(Request.QueryString("SubCat1").ToString))
                    fillURL(RemoveLiterals(DecodeURL(Request.QueryString("SubCat1"))))
                    fillMainCat(RemoveLiterals(Session("MainCat")))
                    fillSubCat1(RemoveLiterals(Session("SubCat1")))
                    ' ''Session("URL1") = "<a href='" & ResolveUrl("~/main/" & EncodeURL(Session("MainCat").ToString) & "/" & ReturnValue("Select CategoryName from Category_Distinct where Category_KId='" & Session("MainCat").ToString & "'") & ".aspx") & "'>" & ReturnValue("Select Category_Name from Category_Distinct where Category_KId='" & RemoveLiterals(Session("MainCat")) & "'") & "</a> > "
                    '' '' Session("URL1") = "<a href='" & ResolveUrl("~/main/" & EncodeURL(e.Row.Cells(1).Text) & "/" & e.Row.Cells(2).Text & ".aspx" & "'>" & ReturnValue("Select Category_Name from Category_Distinct where Category_KId='" & RemoveLiterals(Session("MainCat")) & "'") & "</a> > "
                    ' ''Session("URL2") = "<a href='" & Request.RawUrl & "'>" & ReturnValue("Select Category_Name from CategoryDistinct where Category_KId='" & RemoveLiterals(Session("SubCat1")) & "'") & "</a> > "
                    ' ''td.InnerHtml = ""
                    ' ''td.InnerHtml = Session("URL1").ToString & Session("URL2").ToString
                    ' ''Session("URL") = td.InnerHtml.ToString
                    Session("Title1") = ReturnValue("Select Category_Name from Category_Distinct where Category_KId='" & RemoveLiterals(Session("MainCat")) & "'") & " - Atcomaart Industrial Supply"
                    Session("Title2") = ReturnValue("Select Category_Name from CategoryDistinct where Category_KId='" & RemoveLiterals(Session("SubCat1")) & "'")
                    Page.Title = StrConv(Session("Title2").ToString, VbStrConv.ProperCase) & ", " & StrConv(Session("Title1").ToString, VbStrConv.ProperCase)
                    Session("Title") = Page.Title
                    FillMeta(RemoveLiterals(Session("SubCat1")))



                    'Session("URL") = td.InnerHtml.ToString
                    'td.InnerHtml = TextBox1.Text & "<a href='" & Request.RawUrl & "'>" & ReturnValue("Select Category_Name from Category_Distinct where Category_KId='" & RemoveLiterals(Session("SubCat1")) & "'") & "</a> > "
                    'TextBox1.Text = td.InnerHtml
                End If

                If Request.QueryString("SubCat2") <> Nothing Then

                    Session("MainCat1") = Nothing
                    Session("SubCat2") = RemoveLiterals(DecodeURL(Request.QueryString("SubCat2").ToString))
                    'fillMainCat(Session("MainCat"))
                    'fillSubCat1(Session("SubCat1"))
                    fillURL(RemoveLiterals(DecodeURL(Request.QueryString("SubCat2"))))
                    fillsubCat2(RemoveLiterals(Session("SubCat2").ToString))

                    Session("URL1") = "<a href='" & ResolveUrl("~/main/" & EncodeURL(RemoveLiterals(Session("MainCat").ToString)) & "/" & ReturnValue("Select CategoryName from Category_Distinct where Category_KId='" & RemoveLiterals(Session("MainCat").ToString) & "'") & ".aspx") & "'>" & ReturnValue("Select Category_Name from Category_Distinct where Category_KId='" & RemoveLiterals(Session("MainCat")) & "'") & "</a> > "
                    Dim strCat2 As String
                    strCat2 = ReturnValue("Select Category_KId from CategoryDistinct where Category_KId='" & RemoveLiterals(ReturnValue("Select Category_ParentId from CategoryDistinct where Category_KId='" & RemoveLiterals(Session("SubCat2").ToString) & "'")) & "'")
                    ' ''Session("URL2") = "<a href='" & ResolveUrl("~/s2/" & EncodeURL(strCat2.ToString) & "/" & ReturnValue("Select CategoryName from Category_Distinct where Category_KId='" & Session("MainCat").ToString & "'") & "/" & ReturnValue("Select Category_Name from Category_Master where Category_KId='" & strCat2 & "'") & ".aspx") & "'>" & ReturnValue("Select CategoryName from CategoryDistinct where Category_KId='" & RemoveLiterals(strCat2) & "'") & "</a> > "
                    '' ''CType(e.Row.Cells(0).FindControl("LinkButton1"), HyperLink).NavigateUrl = Server.HtmlEncode(ResolveUrl("~/s2/" & EncodeURL(RemoveLiterals(strCatID)) & "/" & e.Row.Cells(3).Text & "/" & e.Row.Cells(2).Text & ".aspx"))

                    ' ''Session("URL3") = "<a href='" & Request.RawUrl & "'>" & ReturnValue("Select Category_Name from CategoryDistinct where Category_KId='" & RemoveLiterals(Session("SubCat2")) & "'") & "</a> > "
                    ' ''td.InnerHtml = ""
                    ' ''td.InnerHtml = Session("URL1").ToString & Session("URL2").ToString & Session("URL3")
                    ' ''Session("URL") = td.InnerHtml.ToString
                    Session("Title1") = ReturnValue("Select Category_Name from Category_Distinct where Category_KId='" & RemoveLiterals(Session("MainCat")) & "'") & " - Atcomaart Industrial Supply"
                    Session("Title2") = ReturnValue("Select Category_Name from CategoryDistinct where Category_KId='" & RemoveLiterals(strCat2) & "'")
                    Session("Title3") = ReturnValue("Select Category_Name from CategoryDistinct where Category_KId='" & RemoveLiterals(Session("SubCat2")) & "'")
                    Page.Title = StrConv(Session("Title3").ToString, VbStrConv.ProperCase) & ", " & StrConv(Session("Title2").ToString, VbStrConv.ProperCase) & ", " & StrConv(Session("Title1").ToString, VbStrConv.ProperCase)
                    Session("Title") = Page.Title
                    FillMeta(RemoveLiterals(Session("SubCat2")))



                    'Session("URL") = td.InnerHtml.ToString
                    'td.InnerHtml = TextBox1.Text & "<a href='" & Request.RawUrl & "'>" & ReturnValue("Select Category_Name from Category_Distinct where Category_KId='" & RemoveLiterals(Session("SubCat1")) & "'") & "</a> > "
                    'TextBox1.Text = td.InnerHtml
                End If

            End If


            ' ''Dim scatid As String
            ' ''Dim scatid1 As String
            ' ''scatid = Request.QueryString("gvid")
            ' ''If scatid = Nothing Then
            ' ''    If Not IsPostBack Then
            ' ''        catid = DecodeURL(Request.QueryString("catid"))
            ' ''        Session("mcat") = catid
            ' ''        valuee1 = ""
            ' ''        valuee2 = ""
            ' ''        valuee3 = ""
            ' ''        Label1.Text = ""
            ' ''        loadcategory()
            ' ''        GridView2.SelectedIndex = -1
            ' ''    End If
            ' ''Else
            ' ''    If scatid <> Nothing Then
            ' ''        scatid1 = scatid.Substring(0, scatid.IndexOf("-"))
            ' ''        catid = scatid.Substring(scatid.IndexOf("-") + 1)
            ' ''        'Session("catid") = Nothing
            ' ''        If scatid1 = "main" Then
            ' ''            Session("mcat") = catid
            ' ''            loadcategory()
            ' ''            GridView2.SelectedIndex = -1
            ' ''        ElseIf scatid1 = "sub1" Then
            ' ''            Session("catid") = catid
            ' ''            loadcategory()
            ' ''            If Session("grd2") < 0 Then
            ' ''                Session("grd2") = Nothing
            ' ''            End If

            ' ''            ' fillsubgrid()
            ' ''            LinkButton1_Click(Session("mcat"))
            ' ''            LinkButton2_Click(Session("catid"))
            ' ''            Session("sub1catid") = Session("catid")
            ' ''        ElseIf scatid1 = "sub2" Then
            ' ''            Session("sub2catid") = catid
            ' ''            LinkButton2_Click(Session("sub1catid"))
            ' ''            LinkButton3_Click(Session("sub2catid"))
            ' ''        End If


            ' ''    Else

            ' ''    End If
            ' ''End If

        Catch ex As Exception

        End Try
    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
            td.InnerHtml = "You Are Here > "
            td.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
                    Session("MainCat") = dr1(0).Item("Category_ParentId").ToString
                    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

        td.InnerHtml = "You Are Here > "
        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
                td.InnerHtml = url1(0).ToString
                Continue For
            Else
                td.InnerHtml += url1(i).Replace("JJJ", "s" & i + 1)
            End If
        Next
        td.InnerHtml = "You Are Here > " & td.InnerHtml

        Dim str As String
        str = "Hello"


        ' ''Dim Cat_ID As ArrayList = New ArrayList
        ' ''Cat_ID.Add(Cat_KID)
        ' ''Dim Name As String
        ' ''Name = ReturnValue("Select Category_ParentId from Category_Master where Category_KID='" & RemoveLiterals(Cat_KID) & "'")
        ' ''While Name <> "Root Category"
        ' ''    Cat_ID.Add(Name)
        ' ''    Name = ReturnValue("Select Category_ParentId from Category_Master where Category_KID='" & RemoveLiterals(Name) & "'")
        ' ''    'Cat_ID(i) = ReturnValue("Select Category_KId from Category_Master where Category_KID='" & RemoveLiterals(Cat_KID) & "'")
        ' ''End While
        ' ''Cat_ID.Reverse()
        ' ''td.InnerHtml = ""
        ' ''Dim i As Integer
        ' ''For i = 0 To Cat_ID.Count - 1
        ' ''    If i = 0 Then
        ' ''        td.InnerHtml += "<a href='" & ResolveUrl("~/main/" & EncodeURL(RemoveLiterals(Cat_ID(i).ToString)) & "/" & ReturnValue("Select CategoryName from Category_Distinct where Category_Kid='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & ".aspx") & "' >" & ReturnValue("Select Category_Name from Category_Distinct where Category_KId ='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & "</a> > "
        ' ''        Session("MainCat") = RemoveLiterals(Cat_ID(i).ToString)
        ' ''    ElseIf i = 1 Then
        ' ''        Session("SubCat1") = RemoveLiterals(Cat_ID(i).ToString)
        ' ''        If ReturnValue("Select CategoryName from CategoryDistinct where Category_ParentId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") <> "" Then
        ' ''            td.InnerHtml += "<a href='" & ResolveUrl("~/s2/" & EncodeURL(RemoveLiterals(Cat_ID(i).ToString)) & "/" & ReturnValue("Select CategoryName from Category_Distinct where Category_KId='" & RemoveLiterals(Cat_ID(i - 1).ToString) & "'") & "/" & ReturnValue("Select CategoryName from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & ".aspx") & "'>" & ReturnValue("Select Category_Name from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & "</a> > "
        ' ''        Else
        ' ''            td.InnerHtml += "<a href='" & ResolveUrl("~/category/" & EncodeURL(RemoveLiterals(Cat_ID(i).ToString)) & "/" & ReturnValue("Select CategoryName from Category_Distinct where Category_KId='" & RemoveLiterals(Cat_ID(i - 1).ToString) & "'") & "/" & ReturnValue("Select CategoryName from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & ".aspx") & "'>" & ReturnValue("Select Category_Name from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & "</a> > "
        ' ''        End If
        ' ''    ElseIf i = 2 Then
        ' ''        Session("SubCat2") = RemoveLiterals(Cat_ID(i).ToString)
        ' ''        If ReturnValue("Select CategoryName from CategoryDistinct where Category_ParentId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") <> "" Then
        ' ''            td.InnerHtml += "<a href='" & ResolveUrl("~/s3/" & EncodeURL(RemoveLiterals(Cat_ID(i).ToString)) & "/" & ReturnValue("Select CategoryName from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i - 1).ToString) & "'") & "/" & ReturnValue("Select CategoryName from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & ".aspx") & "'>" & ReturnValue("Select Category_Name from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & "</a> > "
        ' ''        Else
        ' ''            td.InnerHtml += "<a href='" & ResolveUrl("~/category/" & EncodeURL(RemoveLiterals(Cat_ID(i).ToString)) & "/" & ReturnValue("Select CategoryName from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i - 1).ToString) & "'") & "/" & ReturnValue("Select CategoryName from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & ".aspx") & "'>" & ReturnValue("Select Category_Name from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & "</a> > "
        ' ''        End If
        ' ''    ElseIf i = 3 Then
        ' ''        Session("MainCat1") = Cat_ID(i).ToString
        ' ''        If ReturnValue("Select CategoryName from CategoryDistinct where Category_ParentId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") <> "" Then
        ' ''            td.InnerHtml += "<a href='" & ResolveUrl("~/s4/" & EncodeURL(RemoveLiterals(Cat_ID(i).ToString)) & "/" & ReturnValue("Select CategoryName from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i - 1).ToString) & "'") & "/" & ReturnValue("Select CategoryName from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & ".aspx") & "'>" & ReturnValue("Select Category_Name from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & "</a> > "
        ' ''        Else
        ' ''            td.InnerHtml += "<a href='" & ResolveUrl("~/category/" & EncodeURL(RemoveLiterals(Cat_ID(i).ToString)) & "/" & ReturnValue("Select CategoryName from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i - 1).ToString) & "'") & "/" & ReturnValue("Select CategoryName from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & ".aspx") & "'>" & ReturnValue("Select Category_Name from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & "</a> > "
        ' ''        End If
        ' ''    ElseIf i = 4 Then
        ' ''        If ReturnValue("Select CategoryName from CategoryDistinct where Category_ParentId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") <> "" Then
        ' ''            td.InnerHtml += "<a href='" & ResolveUrl("~/s5/" & EncodeURL(RemoveLiterals(Cat_ID(i).ToString)) & "/" & ReturnValue("Select CategoryName from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i - 1).ToString) & "'") & "/" & ReturnValue("Select CategoryName from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & ".aspx") & "'>" & ReturnValue("Select Category_Name from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & "</a> > "
        ' ''        Else
        ' ''            td.InnerHtml += "<a href='" & ResolveUrl("~/category/" & EncodeURL(RemoveLiterals(Cat_ID(i).ToString)) & "/" & ReturnValue("Select CategoryName from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i - 1).ToString) & "'") & "/" & ReturnValue("Select CategoryName from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & ".aspx") & "'>" & ReturnValue("Select Category_Name from CategoryDistinct where Category_KId='" & RemoveLiterals(Cat_ID(i).ToString) & "'") & "</a> > "
        ' ''        End If
        ' ''    End If
        ' ''Next


    End Sub
    Public Function limitWords(ByVal str As String, ByVal words As Integer, ByVal chars As Integer, ByVal delimiter As String) As String
        If (chars) Then
            If (str.Length() > chars) Then
                str = str.Substring(0, chars)
            End If
        End If

        If (words) Then
            Dim temp() As String
            temp = str.Split(" ")

            If (temp.Length > words) Then
                Array.Resize(temp, words)

            End If
            Dim i As Integer = 0
            str = ""
            While (i < temp.Length)
                ' If temp(i) <> "" Then
                str += temp(i) & delimiter
                i = i + 1
                ' End If

            End While
        End If
        Return str
    End Function
    Public Sub FillMeta(ByVal strCatID As String)



        Dim dt As DataTable
        dt = ReturnDataTable("Select top(5) Category_Name from CategoryDistinct where Category_ParentId='" & strCatID & "' order by Category_Name")
        Dim i As Integer
        Dim strDiscription As String = ""
        Dim strKeyWords As String = ""
        For i = 0 To dt.Rows.Count - 1
            strDiscription &= dt.Rows(i)("Category_Name").ToString & ", "
            strKeyWords &= dt.Rows(i)("Category_Name").ToString & ", "
        Next

        Dim mt1 As New HtmlMeta
        mt1.Name = "description"
        strDiscription = "Find " & strDiscription & Page.Title.Remove(Page.Title.LastIndexOf("-")).Replace(",", " ") & " and various other industrial and business supply products only at atcomaart.com"
        mt1.Content = strDiscription
        'limitWords(strDiscription, 0, 256, " ")
        '
        'mt1.Content = "Find " &  & Page.Title & " and various other industrial and business supply products only at atcomaart.com"

        Page.Header.Controls.Add(mt1)

        Dim mt2 As New HtmlMeta
        mt2.Name = "keywords"
        mt2.Content = strKeyWords & "," & Page.Title.Remove(Page.Title.LastIndexOf("-"))
        'limitWords(strKeyWords & Page.Title.Remove(Page.Title.LastIndexOf("-")), 0, 256, " ")
        Page.Header.Controls.Add(mt2)

    End Sub
    Public Sub fillSubCat1(ByVal strSubCat1 As String)
        'Dim dt As DataTable

        dtCategoryDistinct.DefaultView.RowFilter = "Category_ParentId='" & RemoveLiterals(strSubCat1) & "'"
        'dt = ReturnDataTable("Select * from CategoryDistinct where Category_ParentId='" & RemoveLiterals(strSubCat1) & "' order by CategoryName")
        Gridview3.Columns(1).Visible = True
        Gridview3.Columns(2).Visible = True
        Gridview3.Columns(3).Visible = True
        Gridview3.DataSource = dtCategoryDistinct.DefaultView.ToTable
        Gridview3.DataBind()
        Gridview3.Columns(1).Visible = False
        Gridview3.Columns(2).Visible = False
        Gridview3.Columns(3).Visible = False
        'dt = Nothing

    End Sub
    Public Sub fillsubCat2(ByVal strSubCat2 As String)
        'Dim dt As DataTable

        'If IsNothing(Session("CategoryDistinct")) Then
        '    Session("CategoryDistinct") = ReturnDataTable("Select * from CategoryDistinct")
        '    dt = CType(Session("CategoryDistinct"), DataTable)
        'Else
        '    dt = CType(Session("CategoryDistinct"), DataTable)
        'End If
        dtCategoryDistinct.DefaultView.RowFilter = "Category_ParentId='" & RemoveLiterals(strSubCat2) & "'"

        'dt = ReturnDataTable("Select * from CategoryDistinct where Category_ParentId='" & RemoveLiterals(strSubCat2) & "' order by CategoryName")
        GridView1.Columns(1).Visible = True
        GridView1.Columns(2).Visible = True
        GridView1.Columns(3).Visible = True
        GridView1.DataSource = dtCategoryDistinct.DefaultView.ToTable
        GridView1.DataBind()
        GridView1.Columns(1).Visible = False
        GridView1.Columns(2).Visible = False
        GridView1.Columns(3).Visible = False
    End Sub
    Public Sub fillMainCat(ByVal strMainCat As String)


        Dim dt As DataTable
        dt = ReturnDataTable("Select * from Category_Distinct order by Category_Name")
        GridView1.Columns(1).Visible = True
        GridView1.Columns(2).Visible = True
        GridView1.Columns(3).Visible = True
        GridView1.DataSource = dt
        GridView1.DataBind()
        GridView1.Columns(1).Visible = False
        GridView1.Columns(2).Visible = False
        GridView1.Columns(3).Visible = False

        dt = Nothing

        'If IsNothing(Session("CategoryDistinct")) Then
        '    Session("CategoryDistinct") = ReturnDataTable("Select * from CategoryDistinct")
        '    dt = CType(Session("CategoryDistinct"), DataTable)
        'Else
        '    dt = CType(Session("CategoryDistinct"), DataTable)
        'End If
        dtCategoryDistinct.DefaultView.RowFilter = "Category_ParentId='" & RemoveLiterals(strMainCat) & "'"
        'dt = ReturnDataTable("Select * from CategoryDistinct where Category_ParentId='" & RemoveLiterals(strMainCat) & "' order by CategoryName")
        Gridview2.Columns(1).Visible = True
        Gridview2.Columns(2).Visible = True
        Gridview2.Columns(3).Visible = True
        Gridview2.DataSource = dtCategoryDistinct.DefaultView.ToTable
        Gridview2.DataBind()
        Gridview2.Columns(1).Visible = False
        Gridview2.Columns(2).Visible = False
        Gridview2.Columns(3).Visible = False


        dt = Nothing




        'GridView1.SelectedIndex = 5


    End Sub
    Public Sub fillMainCat1(ByVal strMainCat As String)


        '''Dim dt As DataTable
        'dt = ReturnDataTable("Select * from Category_Distinct order by Category_Name")
        'GridView1.Columns(1).Visible = True
        'GridView1.Columns(2).Visible = True
        'GridView1.Columns(3).Visible = True
        'GridView1.DataSource = dt
        'GridView1.DataBind()
        'GridView1.Columns(1).Visible = False
        'GridView1.Columns(2).Visible = False
        'GridView1.Columns(3).Visible = False

        'dt = Nothing

        ' ''If IsNothing(Session("CategoryDistinct")) Then
        ' ''    Session("CategoryDistinct") = ReturnDataTable("Select * from CategoryDistinct")
        ' ''    dt = CType(Session("CategoryDistinct"), DataTable)
        ' ''Else
        ' ''    dt = CType(Session("CategoryDistinct"), DataTable)
        ' ''End If
        dtCategoryDistinct.DefaultView.RowFilter = "Category_ParentId='" & RemoveLiterals(strMainCat) & "'"

        'dt = ReturnDataTable("Select * from CategoryDistinct where Category_ParentId='" & RemoveLiterals(strMainCat) & "' order by CategoryName")
        Gridview2.Columns(1).Visible = True
        Gridview2.Columns(2).Visible = True
        Gridview2.Columns(3).Visible = True
        Gridview2.DataSource = dtCategoryDistinct.DefaultView.ToTable
        Gridview2.DataBind()
        Gridview2.Columns(1).Visible = False
        Gridview2.Columns(2).Visible = False
        Gridview2.Columns(3).Visible = False


        'dt = Nothing




        'GridView1.SelectedIndex = 5


    End Sub
    '    Private Sub loadcategory()
    '        Try
    '            Dim Strr As String
    '            Strr = ReturnValue("select Category_ParentId from Category_Master where Category_Kid ='" & Session("mcat") & "'")

    '            If Strr <> "Root Category" And Not IsNothing(Session("mcat")) Then
    '                Dim Str As String
    '                Str = "select Category_Kid,Category_Name from Category_Master where Category_ParentId='" & Session("sub2catid") & "' order by category_name asc"
    '                If con.State = Data.ConnectionState.Open Then
    '                    con.Close()
    '                End If
    '                con.Open()
    '                Dim cmd As New SqlCommand(Str, con)
    '                Dim adp As New SqlDataAdapter
    '                Dim ds As New DataSet
    '                adp.SelectCommand = cmd
    '                adp.Fill(ds)
    '                GridView1.DataSource = ds
    '                GridView1.DataBind()
    '                Dim i As Integer
    '                Dim pcount As Integer
    '                pcount = GridView1.PageCount
    '                Dim j As Integer
    '                For j = 0 To GridView1.PageCount - 1
    '                    GridView1.PageIndex = j
    '                    GridView1.DataSource = ds
    '                    GridView1.DataBind()
    '                    For i = 0 To GridView1.Rows.Count - 1
    '                        Dim lnk As New HyperLink
    '                        lnk = GridView1.Rows(i).FindControl("LinkButton1")
    '                        'lnk.NavigateUrl
    '                        If (lnk.NavigateUrl = Page.ResolveUrl("Search.aspx?gvid=main-" & Session("mcat"))) Then
    '                            GridView1.SelectedIndex = i
    '                            Label1.Text = lnk.Text & "  -  "
    '                            valuee1 = Label1.Text
    '                            'fillsubgrid()
    '                            Exit For
    '                        End If
    '                    Next

    '                Next

    '                LinkButton1_Click(Session("mcat"))
    '            Else
    '                Dim Str As String
    '                If Session("mcat") = Nothing Then
    '                    Dim maincat As String = ReturnValue("select Category_ParentId from Category_Master where Category_Kid='" & Session("catid") & "' and category_isdeleted='0' order by category_name asc")
    '                    Session("mcat") = maincat
    '                Else

    '                End If

    '                Str = "select Category_Kid,Category_Name from Category_Master where Category_ParentId='Root Category' and category_isdeleted='0' order by category_name asc"
    '                If con.State = Data.ConnectionState.Open Then
    '                    con.Close()
    '                End If
    '                con.Open()
    '                Dim cmd As New SqlCommand(Str, con)
    '                Dim adp As New SqlDataAdapter
    '                Dim ds As New DataSet
    '                adp.SelectCommand = cmd
    '                adp.Fill(ds)
    '                GridView1.DataSource = ds
    '                GridView1.DataBind()
    '                Dim i As Integer
    '                Dim pcount As Integer
    '                pcount = GridView1.PageCount
    '                Dim j As Integer
    '                For j = 0 To GridView1.PageCount - 1
    '                    GridView1.PageIndex = j
    '                    GridView1.DataSource = ds
    '                    GridView1.DataBind()
    '                    For i = 0 To GridView1.Rows.Count - 1
    '                        Dim lnk As New HyperLink
    '                        lnk = GridView1.Rows(i).FindControl("LinkButton1")
    '                        'lnk.NavigateUrl
    '                        If (lnk.NavigateUrl = Page.ResolveUrl("Search.aspx?gvid=main-" & Session("mcat"))) Then
    '                            GridView1.SelectedIndex = i
    '                            Label1.Text = lnk.Text & "  -  "
    '                            valuee1 = Label1.Text

    '                            fillsubgrid()
    '                            GoTo lab
    '                        End If
    '                    Next

    '                Next

    'lab:
    '                con.Close()
    '            End If

    '        Catch ex As Exception
    '            ex.Message.ToString()
    '        End Try
    '    End Sub

    '    Public Sub fillsubgrid()
    '        Dim con1 As New SqlConnection
    '        con1.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
    '        Dim Strr As String

    '        Dim lnk As New HyperLink
    '        lnk = GridView1.Rows(GridView1.SelectedIndex).FindControl("LinkButton1")
    '        Dim subcatid As String
    '        subcatid = lnk.NavigateUrl.Substring(lnk.NavigateUrl.IndexOf("-") + 1)
    '        ViewState("subcatid") = subcatid
    '        Strr = "select Category_Kid,Category_Name from Category_Master where Category_ParentId ='" & ViewState("subcatid").ToString.Trim & "' and category_isdeleted='0' order by category_name asc"
    '        If con1.State = Data.ConnectionState.Open Then
    '            con1.Close()
    '        End If
    '        con1.Open()
    '        Dim cmd1 As New SqlCommand(Strr, con1)
    '        'Dim dr1 As SqlDataReader
    '        Dim adp As New SqlDataAdapter
    '        Dim ds As New DataSet
    '        adp.SelectCommand = cmd1
    '        adp.Fill(ds)
    '        GridView2.DataSource = ds
    '        GridView2.DataBind()
    '        GridView2.PageIndex = Session("grd2")
    '        GridView2.SelectedIndex = 0
    '        'ds.Clear()
    '        'ViewState("subcatid") = Nothing
    '        con1.Close()
    '    End Sub


    '    Public Sub filllastgrid()
    '        Dim con1 As New SqlConnection
    '        con1.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
    '        Dim Strr3 As String
    '        Dim lnk As New HyperLink
    '        lnk = GridView2.Rows(GridView2.SelectedIndex).FindControl("LinkButton2")
    '        Dim subcatid3 As String
    '        subcatid3 = lnk.NavigateUrl.Substring(lnk.NavigateUrl.IndexOf("-") + 1)
    '        ViewState("subcatid3") = subcatid3
    '        Strr3 = "select Category_Kid,Category_Name from Category_Master where Category_ParentId ='" & ViewState("subcatid3") & "' and category_isdeleted='0' order by category_Name asc"
    '        If con1.State = Data.ConnectionState.Open Then
    '            con1.Close()
    '        End If
    '        con1.Open()
    '        Dim cmd3 As New SqlCommand(Strr3, con1)
    '        'Dim dr1 As SqlDataReader
    '        Dim adp As New SqlDataAdapter
    '        Dim ds As New DataSet
    '        adp.SelectCommand = cmd3
    '        adp.Fill(ds)
    '        GridView3.DataSource = ds
    '        GridView3.DataBind()
    '        ds.Clear()
    '        con1.Close()
    '    End Sub
    'Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
    '    Try
    '        If GridView1.Rows.Count > 0 Then
    '            GridView1.PageIndex = e.NewPageIndex
    '            loadcategoryyy()
    '        End If
    '        Dim dt As New DataTable
    '        GridView3.DataSource = dt
    '        GridView3.DataBind()
    '        GridView1.SelectedIndex = 0
    '        Dim lnk As New HyperLink
    '        lnk = GridView1.Rows(GridView1.SelectedIndex).FindControl("LinkButton1")
    '        Label1.Text = lnk.Text
    '        fillsubgrid()
    '    Catch ex As Exception

    '    End Try
    'End Sub

    'Private Sub loadcategoryyy()
    '    Try
    '        Dim con As New SqlConnection
    '        con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
    '        Dim Str As String
    '        Str = "select Category_Kid,Category_Name from Category_Master where Category_ParentId='Root Category' and category_isdeleted='0' order by category_name asc"
    '        If con.State = Data.ConnectionState.Open Then
    '            con.Close()
    '        End If
    '        con.Open()
    '        Dim cmd As New SqlCommand(Str, con)
    '        Dim adp As New SqlDataAdapter
    '        Dim ds As New DataSet
    '        adp.SelectCommand = cmd
    '        adp.Fill(ds)
    '        GridView1.DataSource = ds
    '        GridView1.DataBind()
    '        GridView1.SelectedIndex = 0
    '        con.Close()
    '    Catch ex As Exception
    '        ex.Message.ToString()
    '    End Try
    'End Sub
    'Protected Sub GridView2_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView2.PageIndexChanging
    '    Try
    '        If e.NewPageIndex >= 0 Then
    '            GridView2.PageIndex = e.NewPageIndex
    '        Else
    '            GridView2.PageIndex = 0
    '        End If
    '        Session("grd2") = GridView2.PageIndex
    '        fillsubgrid()
    '        filllastgrid()


    '    Catch ex As Exception

    '    End Try
    'End Sub
    'Protected Sub LinkButton1_Click(ByVal subid As String)
    '    Try
    '        Dim lnk As New HyperLink
    '        ' Session("HLabel") = Nothing
    '        Dim i1 As Integer
    '        For i1 = 0 To GridView1.Rows.Count - 1
    '            Dim lnkk As New HyperLink
    '            lnkk = GridView1.Rows(i1).FindControl("LinkButton1")
    '            If (lnkk.NavigateUrl = Page.ResolveUrl("Search.aspx?gvid=main-" & Session("mcat"))) Then
    '                GridView1.SelectedIndex = i1
    '                valuee1 = ""
    '                Label1.Text = valuee3 & lnkk.Text & "  -  "
    '                valuee1 = Label1.Text
    '                Exit For
    '            End If
    '        Next
    '        Dim con As New SqlConnection
    '        con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
    '        Dim Strr As String
    '        Strr = "select Category_Kid,Category_Name from Category_Master where Category_ParentId ='" & subid & "' and category_isdeleted='0' order by Category_Name"
    '        If con.State = Data.ConnectionState.Open Then
    '            con.Close()
    '        End If
    '        con.Open()
    '        Dim cmd As New SqlCommand(Strr, con)
    '        dr = cmd.ExecuteReader()
    '        If dr.Read Then
    '            Dim adp As New SqlDataAdapter
    '            Dim ds As New DataSet
    '            adp.SelectCommand = cmd
    '            dr.Close()
    '            adp.Fill(ds)
    '            GridView2.DataSource = ds
    '            GridView2.DataBind()
    '            con.Close()
    '            ds.Clear()
    '            'Dim dt As New DataTable
    '            'GridView3.DataSource = dt
    '            'GridView3.DataBind()
    '        Else
    '            Session("HLabel") = Label1.Text

    '            Response.Redirect("SearchProduct.aspx?Product_Id=" & subid)

    '        End If
    '    Catch ex As Exception
    '        ex.Message.ToString()
    '    End Try

    'End Sub

    'Protected Sub LinkButton2_Click(ByVal cid As String)
    '    Try

    '        Dim i1 As Integer

    '        For i1 = 0 To GridView2.Rows.Count - 1
    '            Dim lnkk As New HyperLink
    '            lnkk = GridView2.Rows(i1).FindControl("LinkButton2")
    '            If (lnkk.NavigateUrl = Page.ResolveUrl("Search.aspx?gvid=sub1-" & cid)) Then
    '                GridView2.SelectedIndex = i1
    '                Session("HLabel") = Nothing
    '                valuee2 = ""
    '                Label1.Text = valuee1 & lnkk.Text & "  -  "
    '                valuee2 = Label1.Text
    '                Exit For
    '            End If
    '        Next
    '        Dim con As New SqlConnection
    '        con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
    '        Dim Strr As String
    '        Strr = "select Category_Kid,Category_Name from Category_Master where Category_ParentId ='" & cid & "' and category_isdeleted='0' order by Category_Name"
    '        If con.State = Data.ConnectionState.Open Then
    '            con.Close()
    '        End If
    '        con.Open()
    '        Dim cmd As New SqlCommand(Strr, con)
    '        Dim dr As SqlDataReader
    '        dr = cmd.ExecuteReader
    '        If dr.Read Then
    '            Dim adp As New SqlDataAdapter
    '            Dim ds As New DataSet
    '            adp.SelectCommand = cmd
    '            dr.Close()
    '            adp.Fill(ds)
    '            GridView3.DataSource = ds
    '            GridView3.DataBind()
    '            con.Close()
    '            ds.Clear()
    '        Else
    '            Session("HLabel") = Label1.Text

    '            Response.Redirect("SearchProduct.aspx?Product_Id=" & cid)

    '        End If
    '    Catch ex As Exception
    '        ex.Message.ToString()
    '    End Try
    'End Sub

    'Protected Sub LinkButton3_Click(ByVal trdid As String)
    '    Try
    '        Dim lnk As New HyperLink
    '        Session("HLabel") = Nothing

    '        Dim i1 As Integer

    '        For i1 = 0 To GridView3.Rows.Count - 1
    '            Dim lnkk As New HyperLink
    '            lnkk = GridView3.Rows(i1).FindControl("LinkButton3")
    '            If (lnkk.NavigateUrl = Page.ResolveUrl("Search.aspx?gvid=sub2-" & trdid)) Then
    '                GridView3.SelectedIndex = i1
    '                valuee3 = ""
    '                Label1.Text = valuee2 & lnkk.Text & "  -  "
    '                valuee3 = Label1.Text
    '                Exit For
    '            End If
    '        Next
    '        Dim con As New SqlConnection
    '        con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
    '        Dim Strr As String
    '        Strr = "select Category_Kid,Category_Name from Category_Master where Category_ParentId ='" & trdid & "' and category_isdeleted='0' order by Category_Name"
    '        If con.State = Data.ConnectionState.Open Then
    '            con.Close()
    '        End If
    '        con.Open()
    '        Dim cmd As New SqlCommand(Strr, con)
    '        Dim dr As SqlDataReader
    '        dr = cmd.ExecuteReader
    '        If dr.Read Then
    '            Dim adp As New SqlDataAdapter
    '            Dim ds As New DataSet
    '            adp.SelectCommand = cmd
    '            dr.Close()
    '            adp.Fill(ds)
    '            GridView1.DataSource = ds
    '            GridView1.DataBind()
    '            con.Close()
    '            Dim dt As New DataTable
    '            GridView2.DataSource = dt
    '            GridView2.DataBind()
    '            GridView3.DataSource = dt
    '            GridView3.DataBind()
    '        Else
    '            valuee3 = ""
    '            Session("HLabel") = Label1.Text

    '            Response.Redirect("SearchProduct.aspx?Product_Id=" & trdid)

    '        End If
    '    Catch ex As Exception
    '        ex.Message.ToString()
    '    End Try
    'End Sub

    'Protected Sub GridView3_PageIndexChanging1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView3.PageIndexChanging
    '    Try


    '        GridView3.PageIndex = e.NewPageIndex
    '        filllastgrid()
    '        GridView3.PageIndex = e.NewPageIndex
    '    Catch ex As Exception

    '    End Try
    'End Sub
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then

            Dim strCatID As String
            strCatID = e.Row.Cells(1).Text
            'Dim boolCat As Boolean
            'boolCat = IsAlreadyPresent("Select count(*) from CategoryDistinct where Category_ParentId='" & RemoveLiterals(strCatID) & "'")
            dtCategoryDistinct.DefaultView.RowFilter = "Category_ParentId='" & RemoveLiterals(strCatID) & "'"


            Dim str As String
            str = e.Row.Cells(1).Text
            str = Session("MainCat").ToString

            If Request.QueryString("SubCat2") = Nothing And Request.QueryString("MainCat1") = Nothing Then

                CType(e.Row.Cells(0).FindControl("LinkButton1"), HyperLink).NavigateUrl = ResolveUrl("~/main/" & EncodeURL(RemoveLiterals(e.Row.Cells(1).Text)) & "/" & e.Row.Cells(2).Text & ".aspx")
                'Session("URL1") = "<a href='~/main/" & EncodeURL(e.Row.Cells(1).Text) & "/" & e.Row.Cells(2).Text & ".aspx""'>" & ReturnValue("Select Category_Name from CategoryDistinct where Category_KId='" & RemoveLiterals(Session("SubCat1")) & "'") & "</a> > "
            Else

                If dtCategoryDistinct.DefaultView.ToTable.Rows.Count > 0 Then
                    CType(e.Row.Cells(0).FindControl("LinkButton1"), HyperLink).NavigateUrl = ResolveUrl("~/s4/" & EncodeURL(RemoveLiterals(strCatID)) & "/" & e.Row.Cells(3).Text & "/" & e.Row.Cells(2).Text & ".aspx")
                Else
                    CType(e.Row.Cells(0).FindControl("LinkButton1"), HyperLink).NavigateUrl = ResolveUrl("~/category/" & EncodeURL(RemoveLiterals(strCatID)) & "/" & e.Row.Cells(3).Text & "/" & e.Row.Cells(2).Text & ".aspx")
                End If
            End If

            If Session("MainCat1") = Nothing Then
                If RemoveLiterals(e.Row.Cells(1).Text) = RemoveLiterals(Session("MainCat").ToString) Then
                    e.Row.Font.Bold = True
                    e.Row.BackColor = Drawing.ColorTranslator.FromHtml("#B7CBE3")
                    ' ''Session("URL1") = "<a href='" & ResolveUrl("~/main/" & EncodeURL(e.Row.Cells(1).Text) & "/" & e.Row.Cells(2).Text & ".aspx") & "'>" & ReturnValue("Select Category_Name from Category_Distinct where Category_KId='" & RemoveLiterals(Session("MainCat")) & "'") & "</a> > "
                    ' GridView1.SelectedIndex = e.Row.RowIndex
                End If
            Else
                If RemoveLiterals(e.Row.Cells(1).Text) = RemoveLiterals(Session("MainCat1").ToString) Then
                    e.Row.Font.Bold = True
                    e.Row.BackColor = Drawing.ColorTranslator.FromHtml("#B7CBE3")
                    ' ''Session("URL1") = "<a href='" & ResolveUrl("~/main/" & EncodeURL(e.Row.Cells(1).Text) & "/" & e.Row.Cells(2).Text & ".aspx") & "'>" & ReturnValue("Select Category_Name from Category_Distinct where Category_KId='" & RemoveLiterals(Session("MainCat")) & "'") & "</a> > "
                    ' GridView1.SelectedIndex = e.Row.RowIndex
                End If
            End If



            'Dim str As String
            'str = e.Row.Cells(1).Text

        End If
    End Sub
    Protected Sub Gridview2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles Gridview2.RowDataBound

        If e.Row.RowType = DataControlRowType.DataRow Then

            Dim strCatID As String
            strCatID = RemoveLiterals(e.Row.Cells(1).Text)
            'Dim boolCat As Boolean
            'boolCat = IsAlreadyPresent("Select count(*) from CategoryDistinct where Category_ParentId='" & RemoveLiterals(strCatID) & "'")
            dtCategoryDistinct.DefaultView.RowFilter = "Category_ParentId='" & RemoveLiterals(strCatID) & "'"

            If Session("SubCat1") <> Nothing Then
                If RemoveLiterals(e.Row.Cells(1).Text) = RemoveLiterals(Session("SubCat1").ToString) Then
                    e.Row.Font.Bold = True
                    e.Row.BackColor = Drawing.ColorTranslator.FromHtml("#B7CBE3")
                    ' ''Session("URL2") = "<a href='" & ResolveUrl("~/main/" & EncodeURL(e.Row.Cells(1).Text) & "/" & e.Row.Cells(2).Text & ".aspx") & "'>" & ReturnValue("Select Category_Name from Category_Distinct where Category_KId='" & RemoveLiterals(Session("MainCat")) & "'") & "</a> > "
                End If
            End If

            If dtCategoryDistinct.DefaultView.ToTable.Rows.Count > 0 Then
                CType(e.Row.Cells(0).FindControl("LinkButton1"), HyperLink).NavigateUrl = Server.HtmlEncode(ResolveUrl("~/s2/" & EncodeURL(RemoveLiterals(strCatID)) & "/" & e.Row.Cells(3).Text & "/" & e.Row.Cells(2).Text & ".aspx"))
            Else

                If Session("MainCat") <> Nothing And Session("MainCat") = "00002;W" Then
                    CType(e.Row.Cells(0).FindControl("LinkButton1"), HyperLink).NavigateUrl = ResolveUrl("~/bearings/" & EncodeURL(RemoveLiterals(strCatID)) & "/" & e.Row.Cells(3).Text & "/" & e.Row.Cells(2).Text & ".aspx")
                Else
                    CType(e.Row.Cells(0).FindControl("LinkButton1"), HyperLink).NavigateUrl = ResolveUrl("~/category/" & EncodeURL(RemoveLiterals(strCatID)) & "/" & e.Row.Cells(3).Text & "/" & e.Row.Cells(2).Text & ".aspx")
                End If
            End If


        End If

    End Sub
    Protected Sub Gridview3_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles Gridview3.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim strCatID As String
            strCatID = RemoveLiterals(e.Row.Cells(1).Text)
            'Dim boolCat As Boolean
            'boolCat = IsAlreadyPresent("Select count(*) from CategoryDistinct where Category_ParentId='" & RemoveLiterals(strCatID) & "'")

            dtCategoryDistinct.DefaultView.RowFilter = "Category_ParentId='" & RemoveLiterals(strCatID) & "'"

            If dtCategoryDistinct.DefaultView.ToTable.Rows.Count > 0 Then
                CType(e.Row.Cells(0).FindControl("LinkButton1"), HyperLink).NavigateUrl = ResolveUrl("~/s3/" & EncodeURL(strCatID) & "/" & e.Row.Cells(3).Text & "/" & e.Row.Cells(2).Text & ".aspx")
            Else
                If e.Row.RowType = DataControlRowType.DataRow Then
                    'Dim strCatID As String
                    strCatID = RemoveLiterals(e.Row.Cells(1).Text)
                    Dim boolCat As String
                    boolCat = ReturnValue("Select CategoryName from CategoryDistinct where Category_ParentId='" & RemoveLiterals(strCatID) & "'")
                    If boolCat <> "" Then
                        CType(e.Row.Cells(0).FindControl("LinkButton1"), HyperLink).NavigateUrl = Server.HtmlEncode(ResolveUrl("~/s3/" & EncodeURL(RemoveLiterals(strCatID)) & "/" & e.Row.Cells(3).Text & "/" & e.Row.Cells(2).Text & ".aspx"))
                    Else
                        CType(e.Row.Cells(0).FindControl("LinkButton1"), HyperLink).NavigateUrl = ResolveUrl("~/category/" & EncodeURL(RemoveLiterals(strCatID)) & "/" & e.Row.Cells(3).Text & "/" & e.Row.Cells(2).Text & ".aspx")
                    End If


                End If

                CType(e.Row.Cells(0).FindControl("LinkButton1"), HyperLink).NavigateUrl = ResolveUrl("~/category/" & EncodeURL(strCatID) & "/" & e.Row.Cells(3).Text & "/" & e.Row.Cells(2).Text & ".aspx")
            End If


        End If
    End Sub

End Class
