﻿Imports System
Imports System.Data
Imports System.IO


Partial Class SearchProductIndex
    Inherits System.Web.UI.Page
    Shared dtMain As DataTable
    Shared dtChild As DataTable
    'Dim ProductIndex As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Session("three") = "yes"
        If Not IsPostBack Then
            Try
                'tdProductIndex.InnerHtml = Request.QueryString("ProductIndex").ToString
                'ProductIndex = ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'")
                'dtMain = ReturnDataTable("SELECT     SUM(V1.Count) AS Count, V1.CategoryIndex_Name, V1.Name, Category_Distinct.Category_Name, Category_Distinct.CategoryName,                       REPLACE(LOWER(Category_Distinct.ParentName), ' ', '-') AS Name, Category_Distinct.Category_Kid, V1.CategoryIndex_IsDeleted FROM         V1 left JOIN                       Category_Distinct ON V1.Category_ParentId = Category_Distinct.Category_Kid GROUP BY V1.CategoryIndex_Name, V1.Name, Category_Distinct.Category_Name, Category_Distinct.CategoryName, Category_Distinct.ParentName,                 Category_Distinct.Category_Kid, V1.CategoryIndex_IsDeleted Having (V1.CategoryIndex_IsDeleted = N'0') order by V1.CategoryIndex_Name")

                If (Request.QueryString("ProductIndexPage")) = Nothing Then
                    Session("ProductIndexPage") = 1
                Else
                    Session("ProductIndexPage") = Request.QueryString("ProductIndexPage").ToString
                End If


                If IsNothing(dtChild) And IsNothing(dtMain) Then
                    dtMain = ReturnDataTable("SELECT     CategoryDistinct.Category_ParentName, CategoryDistinct.Category_Kid, CategoryDistinct.Category_Name, CategoryDistinct.Category_ParentId,  CategoryDistinct.ParentName, CategoryDistinct.CategoryName, SUM(V1.Count) AS Count, V1.CategoryIndex_Name, V1.Name FROM V1 INNER JOIN CategoryDistinct ON V1.Category_ParentId = CategoryDistinct.Category_Kid GROUP BY CategoryDistinct.Category_ParentName, CategoryDistinct.Category_Kid, CategoryDistinct.Category_Name, CategoryDistinct.Category_ParentId, CategoryDistinct.ParentName, CategoryDistinct.CategoryName, V1.CategoryIndex_Name, V1.Name order by CategoryDistinct.Category_Name ")
                    dtChild = ReturnDataTable("SELECT     Category_ParentName, Category_Kid, Category_Name, ParentName, CategoryName, Count, CategoryIndex_Name, CategoryIndex_IsDeleted, Category_ParentId, CategoryIndex_Name AS Expr1, CategoryIndex_IsDeleted AS Expr2, Category_ParentId AS Expr3, V1.Name as Name FROM V1 WHERE (CategoryIndex_IsDeleted = N'0')ORDER BY Category_Name")
                End If

                fillgrid()
                HiddenField1.Value = StrConv(ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'").ToString.Trim, VbStrConv.ProperCase)
                If HiddenField1.Value = "" Then
                    HiddenField1.Value = "no product found"
                End If
                Me.Header.Title = "Product Index - " & HiddenField1.Value  'ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'").ToString.Trim & " - Atcomaart Industrial Supply."

              


                
            Catch ex As Exception

            End Try
        End If

    End Sub

    Public Sub fillgrid()
        Try
            Dim dt As DataTable
            'dt = ReturnDataTable("SELECT Category_Name, Category_Kid FROM Category_Master WHERE (Category_Kid IN (SELECT DISTINCT Category_ParentId FROM Category_Master AS Category_Master_1 WHERE (Category_Kid IN (SELECT DISTINCT Category_Kid FROM Category_Index_Master WHERE (CategoryIndex_Name = N'" & ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'").ToString.Trim & "'))))) order by Category_Name")
            'dt = ReturnDataTable("SELECT Category_ParentName, Category_Kid, Category_Name, Category_ParentId, ParentName, CategoryName FROM CategoryDistinct WHERE (Category_Kid IN (SELECT DISTINCT Category_ParentId FROM Category_Master AS Category_Master_1 WHERE (Category_Kid IN (SELECT DISTINCT Category_Kid FROM Category_Index_Master WHERE (CategoryIndex_Name = N'" & ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'").ToString.Trim & "'))))) ORDER BY Category_Name")
            'dt = ReturnDataTable("SELECT     CategoryDistinct.Category_ParentName, CategoryDistinct.Category_Kid, CategoryDistinct.Category_Name, CategoryDistinct.Category_ParentId,                       CategoryDistinct.ParentName, CategoryDistinct.CategoryName, ISNULL(ProductCategoryCount.Expr1, N'0') AS Count FROM         CategoryDistinct LEFT OUTER JOIN                       ProductCategoryCount ON CategoryDistinct.Category_Kid = ProductCategoryCount.Category_ParentId WHERE     (CategoryDistinct.Category_Kid IN                           (SELECT DISTINCT Category_ParentId                             FROM          Category_Master AS Category_Master_1                             WHERE      (Category_Kid IN                                                        (SELECT DISTINCT Category_Kid             FROM Category_Index_Master                                                          WHERE      (CategoryIndex_Name = N'" & ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'").ToString.Trim & "'))))) ORDER BY CategoryDistinct.Category_Name")
            'dt = ReturnDataTable("SELECT     dbo.CategoryDistinct.Category_ParentName, dbo.CategoryDistinct.Category_Kid, dbo.CategoryDistinct.Category_Name,                       dbo.CategoryDistinct.Category_ParentId, dbo.CategoryDistinct.ParentName, dbo.CategoryDistinct.CategoryName, SUM(dbo.V1.Count) AS Count, V1.Name ,            dbo.V1.CategoryIndex_Name FROM         dbo.V1 LEFT OUTER JOIN                       dbo.CategoryDistinct ON dbo.V1.Category_ParentId = dbo.CategoryDistinct.Category_Kid GROUP BY dbo.CategoryDistinct.Category_ParentName, dbo.CategoryDistinct.Category_Kid, dbo.CategoryDistinct.Category_Name,             dbo.CategoryDistinct.Category_ParentId, dbo.CategoryDistinct.ParentName, dbo.CategoryDistinct.CategoryName, dbo.V1.CategoryIndex_Name HAVING      (dbo.V1.CategoryIndex_Name = '" & ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'").ToString.Trim & "')")
            'dt = ReturnDataTable("SELECT     CategoryDistinct.Category_ParentName, CategoryDistinct.Category_Kid, CategoryDistinct.Category_Name, CategoryDistinct.Category_ParentId,                       CategoryDistinct.ParentName, CategoryDistinct.CategoryName, SUM(V1.Count) AS Count, V1.CategoryIndex_Name, V1.Name FROM         V1 INNER JOIN                       CategoryDistinct ON V1.Category_ParentId = CategoryDistinct.Category_Kid GROUP BY CategoryDistinct.Category_ParentName, CategoryDistinct.Category_Kid, CategoryDistinct.Category_Name, CategoryDistinct.Category_ParentId,              CategoryDistinct.ParentName, CategoryDistinct.CategoryName, V1.CategoryIndex_Name, V1.Name HAVING      (V1.CategoryIndex_Name = '" & ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'").ToString.Trim & "')")
            dtMain.DefaultView.RowFilter = "Name ='" & Request.QueryString("ProductIndex").ToString & "'"
            dt = dtMain.DefaultView.ToTable
            Dim i As Integer
            If Request.QueryString("ProductIndexPage") = Nothing Then
                'If dt.Rows.Count = 0 Then
                'dt = ReturnDataTable("SELECT     SUM(V1.Count) AS Count, V1.CategoryIndex_Name, V1.Name, Category_Distinct.Category_Name, Category_Distinct.CategoryName,                       REPLACE(LOWER(Category_Distinct.ParentName), ' ', '-') AS Name, Category_Distinct.Category_Kid, V1.CategoryIndex_IsDeleted FROM         V1 INNER JOIN                       Category_Distinct ON V1.Category_ParentId = Category_Distinct.Category_Kid GROUP BY V1.CategoryIndex_Name, V1.Name, Category_Distinct.Category_Name, Category_Distinct.CategoryName, Category_Distinct.ParentName,                 Category_Distinct.Category_Kid, V1.CategoryIndex_IsDeleted HAVING      (V1.CategoryIndex_Name = '" & ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'").ToString.Trim & "') AND (V1.CategoryIndex_IsDeleted = N'0')")
                'dtMain.DefaultView.RowFilter = "Name ='" & Request.QueryString("ProductIndex").ToString
                'dt = dtMain.DefaultView.ToTable
                'End If
                gvProductIndex.Columns(0).Visible = True
                gvProductIndex.DataSource = dt
                gvProductIndex.DataBind()
                gvProductIndex.Columns(0).Visible = False
                If dt.Rows.Count > 0 Then
                    Dim count As Integer
                    count = 0
                    If dt.Rows.Count > 0 Then
                        'Dim i As Integer
                        For i = 0 To gvProductIndex.Rows.Count - 1
                            count += CType(CType(gvProductIndex.Rows(i).Cells(1).FindControl("maincount"), HtmlGenericControl).InnerText.Replace(" (", "").Replace(")", ""), Integer)

                        Next
                    End If
                    lblHeader.Text += "You Searched >&nbsp; <a href='" & Request.RawUrl.ToString & "' style='color:#082b53;' > " & ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'").ToString.Trim & "&nbsp;<b>(" & count.ToString & ")</b> </a>"
                    If dt.Rows.Count > 10 Then
                        CType(gvProductIndex.FooterRow.Cells(1).FindControl("hrlBack"), HyperLink).Visible = False
                        CType(gvProductIndex.FooterRow.Cells(1).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl & "?productindexpage=" & CType(Session("ProductIndexPage"), Integer) + 1)
                    Else
                        CType(gvProductIndex.FooterRow.Cells(1).FindControl("hrlBack"), HyperLink).Visible = False
                        CType(gvProductIndex.FooterRow.Cells(1).FindControl("hrlNext"), HyperLink).Visible = False
                    End If
                    'NewTopHome1.Visible = True
                    'HomeRightBanner1.Visible = True
                    'HomeBottom1.Visible = True
                    'hr.Visible = True
                    'trback.Visible = True
                    stirp.Visible = True
                Else
                    lblHeader.Text += "" '"<b>Search Result Not Found </b>"
                    tdSearchNotFound.InnerHtml = "<img alt='' src='" & Page.ResolveUrl("~/images/Search_not_Found.GIF") & "' />"
                    stirp.Visible = False
                    'NewTopHome1.Visible = False
                    'HomeRightBanner1.Visible = False
                    'HomeBottom1.Visible = False
                    'hr.Visible = False
                    'trback.Visible = False
                End If


            Else

                Dim count As Integer
                count = 0
               
                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("productindexpage"), 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
                gvProductIndex.Columns(0).Visible = True
                gvProductIndex.DataSource = dtPage
                gvProductIndex.DataBind()
                gvProductIndex.Columns(0).Visible = False
                
                For i = 0 To gvProductIndex.Rows.Count - 1
                    count += CType(CType(gvProductIndex.Rows(i).Cells(1).FindControl("maincount"), HtmlGenericControl).InnerText.Replace(" (", "").Replace(")", ""), Integer)

                Next

                lblHeader.Text += "You Searched >&nbsp; <a href='" & Request.RawUrl.ToString & "' style='color:#082b53;' > " & ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'").ToString.Trim & "&nbsp;<b>(" & count.ToString & ")</b> </a>"
                If gvProductIndex.Rows.Count = 0 Then
                    gvProductIndex.Columns(0).Visible = True
                    gvProductIndex.DataSource = dt
                    gvProductIndex.DataBind()
                    gvProductIndex.Columns(0).Visible = False
                    CType(gvProductIndex.FooterRow.Cells(1).FindControl("hrlBack"), HyperLink).Visible = False
                    CType(gvProductIndex.FooterRow.Cells(1).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?productindexpage")) & "?productindexpage=2")
                Else
                    If dtPage.Rows.Count <= 10 Then
                        CType(gvProductIndex.FooterRow.Cells(1).FindControl("hrlNext"), HyperLink).Visible = False
                        CType(gvProductIndex.FooterRow.Cells(1).FindControl("hrlBack"), HyperLink).Visible = True
                    Else
                        CType(gvProductIndex.FooterRow.Cells(1).FindControl("hrlNext"), HyperLink).Visible = True
                        CType(gvProductIndex.FooterRow.Cells(1).FindControl("hrlBack"), HyperLink).Visible = True
                    End If
                    If Session("ProductIndexPage") = "1" Then
                        CType(gvProductIndex.FooterRow.Cells(1).FindControl("hrlBack"), HyperLink).Visible = False
                    End If
                    Try
                        CType(gvProductIndex.FooterRow.Cells(1).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?productindexpage")) & "?productindexpage=" & CType(Session("ProductIndexPage"), Integer) - 1)
                        CType(gvProductIndex.FooterRow.Cells(1).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl.Remove(Request.RawUrl.IndexOf("?productindexpage")) & "?productindexpage=" & CType(Session("ProductIndexPage"), Integer) + 1)
                    Catch ex As Exception
                        CType(gvProductIndex.FooterRow.Cells(1).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl & "?productindexpage=" & CType(Session("ProductIndexPage"), Integer) - 1)
                        CType(gvProductIndex.FooterRow.Cells(1).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl(Request.RawUrl & "?productindexpage=" & CType(Session("ProductIndexPage"), Integer) + 1)
                    End Try
                End If
            End If


            'If Session("brandpage") = "1" Then
            '    CType(gvProductIndex.FooterRow.Cells(1).FindControl("hrlBack"), HyperLink).Visible = False
            '    CType(gvProductIndex.FooterRow.Cells(1).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl("~/home.aspx?brandpage=" & CType(Session("brandpage"), Integer) + 1)
            'Else
            '    CType(gvbrandsearch.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).Visible = True
            '    CType(gvbrandsearch.FooterRow.Cells(0).FindControl("hrlBack"), HyperLink).NavigateUrl = ResolveUrl("~/home.aspx?brandpage=" & CType(Session("brandpage"), Integer) - 1)
            '    CType(gvbrandsearch.FooterRow.Cells(0).FindControl("hrlNext"), HyperLink).NavigateUrl = ResolveUrl("~/home.aspx?brandpage=" & CType(Session("brandpage"), Integer) + 1)
            'End If







            'Dim count As Integer
            'count = 0
            'If dt.Rows.Count > 0 Then
            '    Dim i As Integer
            '    For i = 0 To dt.Rows.Count - 1
            '        count += CType(dt.Rows(i).Item("Count").ToString, Integer)

            '    Next
            'End If
            '            lblHeader.Text += "&nbsp;&nbsp; <a href='" & Request.RawUrl.ToString & "' style='color:white;' > " & ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'").ToString.Trim & "&nbsp;(" & count.ToString & ") </a>"
            'gvProductIndex.HeaderRow.Cells(1).Text = "Search For :  " & ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'").ToString.Trim
            dt.Dispose()
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub gvProductIndex_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvProductIndex.RowDataBound

        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim dt As DataTable
            'dt = ReturnDataTable("SELECT DISTINCT Category_Index_Master.Category_Kid, Category_Master.Category_Name FROM         Category_Index_Master INNER JOIN                       Category_Master ON Category_Index_Master.Category_Kid = Category_Master.Category_Kid WHERE     (Category_Master.Category_ParentId = N'" & RemoveLiterals(e.Row.Cells(0).Text.ToString).ToString & "') AND (Category_Index_Master.CategoryIndex_IsDeleted = N'0') AND (Category_Master.Category_IsDeleted = N'0') and (Category_Index_Master.CategoryIndex_Name = N'" & ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'").ToString.Trim & "')")
            'dt = ReturnDataTable("SELECT DISTINCT CategoryDistinct.Category_ParentName, CategoryDistinct.Category_Kid, CategoryDistinct.Category_Name, CategoryDistinct.Category_ParentId,              CategoryDistinct.ParentName, CategoryDistinct.CategoryName FROM         Category_Index_Master LEFT OUTER JOIN                       CategoryDistinct ON Category_Index_Master.Category_Kid = CategoryDistinct.Category_Kid WHERE     (Category_Index_Master.CategoryIndex_IsDeleted = N'0') AND (Category_Index_Master.CategoryIndex_Name = N'" & ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'").ToString.Trim & "') AND                        (CategoryDistinct.Category_ParentId = N'" & RemoveLiterals(e.Row.Cells(0).Text.ToString).ToString & "')")
            'dt = ReturnDataTable("SELECT DISTINCT                       CategoryDistinct.Category_ParentName, CategoryDistinct.Category_Kid, CategoryDistinct.Category_Name, CategoryDistinct.Category_ParentId,                       CategoryDistinct.ParentName, CategoryDistinct.CategoryName, ISNULL(ProductCategoryCount.Expr1, N'0') AS Count FROM         ProductCategoryCount RIGHT OUTER JOIN                       CategoryDistinct ON ProductCategoryCount.Product_CategoryId = CategoryDistinct.Category_Kid RIGHT OUTER JOIN                       Category_Index_Master ON CategoryDistinct.Category_Kid = Category_Index_Master.Category_Kid WHERE     (Category_Index_Master.CategoryIndex_IsDeleted = N'0') AND (Category_Index_Master.CategoryIndex_Name = N'" & ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'").ToString.Trim & "') AND                       (CategoryDistinct.Category_ParentId = N'" & RemoveLiterals(e.Row.Cells(0).Text.ToString).ToString & "')")
            'dt = ReturnDataTable("SELECT DISTINCT                       CategoryDistinct.Category_ParentName, CategoryDistinct.Category_Kid, CategoryDistinct.Category_Name, CategoryDistinct.Category_ParentId, CategoryDistinct.ParentName, CategoryDistinct.CategoryName, COUNT(Product_Information.Product_CategoryId) AS Count,Category_Index_Master.CategoryIndex_Name, Category_Index_Master.CategoryIndex_IsDeleted FROM         Product_Information RIGHT OUTER JOIN                       Category_Index_Master ON Product_Information.Product_CategoryId = Category_Index_Master.Category_Kid LEFT OUTER JOIN                       CategoryDistinct ON Category_Index_Master.Category_Kid = CategoryDistinct.Category_Kid GROUP BY CategoryDistinct.Category_ParentName, CategoryDistinct.CategoryName, CategoryDistinct.ParentName, CategoryDistinct.Category_Name,                        CategoryDistinct.Category_Kid, Product_Information.Product_CategoryId, CategoryDistinct.Category_ParentId,              Category_Index_Master.CategoryIndex_Name, Category_Index_Master.CategoryIndex_IsDeleted HAVING      (Category_Index_Master.CategoryIndex_IsDeleted = N'0') AND (Category_Index_Master.CategoryIndex_Name = N'" & ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'").ToString.Trim & "') AND                        (CategoryDistinct.Category_ParentId = N'" & RemoveLiterals(e.Row.Cells(0).Text.ToString).ToString & "')")
            'dt = ReturnDataTable("SELECT     Category_ParentName, Category_Kid, Category_Name, ParentName, CategoryName, Count, CategoryIndex_Name, CategoryIndex_IsDeleted,                        Category_ParentId, CategoryIndex_Name AS Expr1, CategoryIndex_IsDeleted AS Expr2, Category_ParentId AS Expr3             FROM V1 WHERE     (CategoryIndex_Name = '" & ReturnValue("Select Product_Name from ProductIndex where ProductName='" & Request.QueryString("ProductIndex").ToString.Trim & "'").ToString.Trim & "') AND (CategoryIndex_IsDeleted = N'0') AND (Category_ParentId = N'" & RemoveLiterals(e.Row.Cells(0).Text.ToString).ToString & "')ORDER BY Category_Name")
            dtChild.DefaultView.RowFilter = "Name ='" & Request.QueryString("ProductIndex").ToString & "' and Category_ParentId ='" & RemoveLiterals(e.Row.Cells(0).Text.ToString).ToString & "'"
            dt = dtChild.DefaultView.ToTable
            Dim i As Integer
            Dim mainCount As Integer = 0
            For i = 0 To dt.Rows.Count - 1
                If CType(dt.Rows(i).Item("Count").ToString, Integer) = 0 Then
                    Dim newcount As String = ReturnValue("SELECT     COUNT(ProductCategory_Master.ProductCategory_ProductID) AS count, Product_Master.Product_IsDeleted, Product_Master.Product_Approved FROM ProductCategory_Master INNER JOIN Product_Master ON ProductCategory_Master.ProductCategory_ProductID = Product_Master.Product_Kid GROUP BY ProductCategory_Master.ProductCategory_CategoryID, Product_Master.Product_IsDeleted, Product_Master.Product_Approved HAVING (ProductCategory_CategoryID = '" & dt.Rows(i).Item("Category_Kid").ToString & "') AND (Product_Master.Product_Approved = N'Y') AND (Product_Master.Product_IsDeleted = N'0')")
                    If newcount <> "" Then
                        dt.Rows(i).Item("Count") = CType(newcount, Integer)

                    End If
                End If
                mainCount += dt.Rows(i).Item("Count")
            Next
            CType(e.Row.FindControl("maincount"), HtmlGenericControl).InnerText = " (" & mainCount.ToString & ")"
            dt.AcceptChanges()
            CType(e.Row.Cells(1).FindControl("dlchildCategory"), DataList).DataSource = dt
            CType(e.Row.Cells(1).FindControl("dlchildCategory"), DataList).DataBind()
            '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
            'CType(e.Row.Cells(1).FindControl("hlParentCategory"), HyperLink).NavigateUrl = ResolveUrl("~/category/" & EncodeURL(RemoveLiterals(e.Row.Cells(0).Text)) & "/" & e.Row.Cells(3).Text & "/" & e.Row.Cells(2).Text & ".aspx")
        End If
        If e.Row.RowType = DataControlRowType.Footer Then
            Dim nextimg, backimg As String
            nextimg = "Images/aroow_inside.jpg"
            backimg = "Images/raroow_inside.jpg"
            CType(e.Row.Cells(0).FindControl("hrlNext"), HyperLink).Text = "Next <img src='" & Page.ResolveUrl(nextimg) & "' alt='Next' style='height: 10px; width: 21px;border:none;' /> "
            CType(e.Row.Cells(0).FindControl("hrlBack"), HyperLink).Text = "<img src='" & Page.ResolveUrl(backimg) & "' alt='Back' style='height: 10px; width: 21px;border:none;' /> Back"
        End If
    End Sub

    Protected Sub dlChildCategory_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then

            ' ''Dim str As String
            ' ''str = e.Item.ItemIndex
            ' ''CType(e.Item.FindControl("tdHide"), HtmlTableCell).InnerText = str
            'If (((e.Item.ItemIndex + 1) Mod 2) = 0) Then
            '    CType(e.Item.FindControl("tdHide"), HtmlTableCell).Visible = False
            'End If

            'str = e.Item.ItemIndex("")


            'Dim dl As New DataList
            'dl = sender
            'Dim str As String
            'str = dl.DataKeys(e.Item.ItemIndex).ToString
            'Dim count As Integer
            'count = ReturnValue("SELECT     COUNT(*) AS Expr1             FROM Product_Information WHERE  (Product_CategoryId = N'" & RemoveLiterals(dl.DataKeys(e.Item.ItemIndex).ToString) & "')")
            'CType(e.Item.FindControl("hlchildcategory"), HyperLink).Text += "&nbsp;&nbsp;(" & count & ")"
            'str = ""
        End If
    End Sub

    Protected Sub dlChildCategory_Unload(ByVal sender As Object, ByVal e As System.EventArgs)



        'Dim dl As DataList
        'dl = sender

        'CType(dl.Items(0).FindControl("tdHide"), HtmlTableCell).InnerText = "asdad"

        '' ''Dim str As String = dl.Items.Count
        '' ''str = ""

        ' ''Dim count As Integer = dl.Items.Count
        ' ''Dim countstart As Integer

        ' ''If (count Mod 2) = 0 Then
        ' ''    countstart = count / 2

        ' ''    For i = countstart To count - 1
        ' ''        CType(dl.Items(i).FindControl("tdHide"), HtmlTableCell).InnerText = i.ToString
        ' ''        'CType(dl.Items(i).FindControl("tdHide"), HtmlTableCell).Visible = False
        ' ''    Next


        ' ''Else








        ' ''End If




    End Sub

    Protected Sub dlChildCategory_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        'Dim dl As DataList
        'dl = sender
        'Dim i As Integer
        ''CType(dl.Items(0).FindControl("tdHide"), HtmlTableCell).InnerText = "asdad"


        'Dim count As Integer = dl.Items.Count
        'Dim countstart As Integer

        'If (count Mod 2) = 0 Then
        '    countstart = count / 2

        '    For i = countstart To count - 1
        '        'CType(dl.Items(i).FindControl("tdHide"), HtmlTableCell).InnerText = i.ToString
        '        CType(dl.Items(i).FindControl("tdHide"), HtmlTableCell).Visible = False
        '    Next


        'ElseIf count <> 1 Then

        '    Dim strCount As String
        '    strCount = count / 2
        '    countstart = Convert.ToInt32(strCount.Remove(strCount.LastIndexOf("."))) 'Convert.ToInt32((count / 2))
        '    countstart = countstart + 1


        '    For i = countstart To count - 1
        '        'CType(dl.Items(i).FindControl("tdHide"), HtmlTableCell).InnerText = i.ToString
        '        CType(dl.Items(i).FindControl("tdHide"), HtmlTableCell).Visible = False
        '    Next

        'End If

    End Sub
End Class
