Imports System.Data
Imports System.Data.SqlClient
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Partial Class Search
    Inherits System.Web.UI.Page
    Shared a As String
    Dim con As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString"))    'Read the ConnectionString from web.config File
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Session("three") = "yes"
        'If Not IsPostBack Then
        '    Dim cmd As New SqlCommand
        '    Dim dr As SqlDataReader
        '    Dim str As String
        '    Dim maincategory As String = ""
        '    Dim subcategory As String = ""
        '    Dim description As String = ""
        '    Dim strarr(3) As String
        '    Dim catid As String = ""
        '    Try
        '        con.Open()
        '        If Request.QueryString("catid") <> Nothing Then

        '            catid = Request.QueryString("catid")
        '        ElseIf Request.QueryString("gvid") <> Nothing Then
        '            catid = Request.QueryString("gvid").Substring(5) 'the kid is fetch from this string

        '            str = "Select Category_ParentId from Category_Master where Category_KId ='" & RemoveLiterals(catid) & "'"
        '            cmd = New SqlCommand(str, con)
        '            dr = cmd.ExecuteReader()
        '            If dr.Read() Then
        '                If dr(0) <> "Root Category" Then
        '                    catid = dr(0) ' For Title including  category herarchy
        '                End If
        '            End If
        '            dr.Close()
        '            End If
        '            If catid <> "" Then

        '                str = "Select Category_Name from Category_Master where Category_KId ='" & RemoveLiterals(catid) & "'"
        '                cmd = New SqlCommand(str, con)
        '                dr = cmd.ExecuteReader()
        '                If dr.Read() Then

        '                    maincategory = limitWords(dr(0), 10, 90, " ")    ' For Title including  category herarchy
        '                End If
        '                dr.Close()
        '                str = "Select Category_Name,Category_Kid from Category_Master where Category_Parentid ='" & RemoveLiterals(catid) & "'"
        '                cmd = New SqlCommand(str, con)
        '                dr = cmd.ExecuteReader()
        '                Dim i As Integer = 0
        '                While dr.Read()
        '                    description = dr(1).ToString
        '                    If subcategory <> "" Then
        '                    subcategory = subcategory + ", " + dr(0).ToString
        '                    Else
        '                        subcategory = dr(0).ToString

        '                    End If

        '                End While
        '                dr.Close()
        '            description = maincategory + ", " + subcategory

        '                con.Close()
        '                description = limitWords(description, 0, 170, " ")    ' For meta description Content 
        '            subcategory = limitWords(subcategory, 20, 900, ", ") ' For Meta Keyword Content Product Name

        '            End If

        '            Me.Header.Title = maincategory

        '            Dim mt1 As New HtmlMeta
        '            mt1.Name = "description"
        '            mt1.Content = description
        '            Me.Header.Controls.Add(mt1)

        '            Dim mt2 As New HtmlMeta
        '        mt2.Name = "keywords"
        '        mt2.Content = subcategory.ToLower
        '            Me.Header.Controls.Add(mt2)




        '    Catch ex As Exception

        '    End Try





        'End If

    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




End Class