﻿Imports System
Imports System.Data
Partial Class CategoryArticle
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then
            FillExisting()
            fillTitleMetaDescription()
        End If

        'Dim dat As DateTime
        'dat = Convert.ToDateTime("02/16/2009")
        'dat.Day.

        'Dim str As String
        'str = ""

    End Sub

    Public Sub FillExisting()
        hlCategoryName.Text = ReturnValue("Select Category_Name from Category_Distinct where Category_Kid ='" & RemoveLiterals(DecodeURL(Request.QueryString("CategoryID").ToString)) & "'") & "  Articles"
        hlCategoryName.NavigateUrl = Request.RawUrl.ToString

        hlMainArticle.Text = "Industrial Articles"
        hlMainArticle.NavigateUrl = ResolveUrl("~/articles.aspx")

        Dim dt As DataTable
        dt = ReturnDataTable("Select * from ArticleTitle where Category_Kid ='" & RemoveLiterals(DecodeURL(Request.QueryString("CategoryID").ToString)) & "' order by Article_PublishDate desc")
        'Dim gv As GridView
        'gv = CType(e.Row.Cells(0).FindControl("gvArticle"), GridView)
        gvArticle.Columns(1).Visible = True
        gvArticle.DataSource = dt
        gvArticle.DataBind()
        gvArticle.Columns(1).Visible = False

        'If (dt.Rows.Count <> 3) Then
        '    CType(e.Row.Cells(0).FindControl("hlMore"), HyperLink).Visible = False
        'End If

    End Sub

    Public Sub fillTitleMetaDescription()
        Dim strTitle As String
        strTitle = ReturnValue("Select Category_Name from Category_Distinct where Category_KId ='" & RemoveLiterals(DecodeURL(Request.QueryString("CategoryID").ToString)) & "'")
        Me.Title = "Articles | " & strTitle & " Articles | www.atcomaart.com "


    End Sub

    Protected Sub gvArticle_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvArticle.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim dt As DataTable
            dt = ReturnDataTable("Select * from ArticleTitle where Article_Kid ='" & RemoveLiterals(e.Row.Cells(1).Text) & "'")
            Dim hl As HyperLink
            hl = CType(e.Row.Cells(0).FindControl("hlArticle"), HyperLink)
            hl.NavigateUrl = Page.ResolveUrl("~/article/" & EncodeURL(dt.Rows(0).Item("Article_Kid").ToString) & "/content/" & dt.Rows(0).Item("CategoryName").ToString & "/" & dt.Rows(0).Item("ArticleTitle").ToString & ".aspx")
            ' NavigateUrl='<%# "~/article/"&EncodeURL(Eval("Article_KId"))&"/"&Eval("CategoryName")&"/content/"&Eval("ArticleTitle")&".aspx" %>'
        End If
    End Sub
End Class
