Imports TTIBlogLibrary Imports System.Data.SqlClient Imports System.Data Imports System.Data.OleDb Partial Class Blogs Inherits System.Web.UI.Page Dim oBlog As New Blog Dim oBlogDAO As New BlogDAO Private dadapter As SqlDataAdapter Private dset As DataSet Private adsource As PagedDataSource Private connstring As String = System.Configuration.ConfigurationManager.GetSection("DSAppSettings")("sqlconnString") Private pos As Integer Protected Sub Page_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If (Not IsPostBack) Then dlArticleBlog.DataSource = GetData("select * from BlogArticle where ArticleID =" & Request.QueryString("ArticleID")) dlArticleBlog.DataBind() dlComments.DataSource = GetData("select * from BlogComments where ArticleID =" & Request.QueryString("ArticleID") & "Order by DateAdded DESC") dlComments.DataBind() Me.ViewState("vs") = 0 End If pos = CInt(Me.ViewState("vs")) databind() End Sub Public Property CurrentPage() As Integer Get If Me.ViewState("CurrentPage") Is Nothing Then Return 0 Else Return Convert.ToInt16(Me.ViewState("CurrentPage").ToString()) End If End Get Set(ByVal value As Integer) Me.ViewState("CurrentPage") = value End Set End Property Private ReadOnly Property ConnectionString() As String Get Return ConfigurationManager.GetSection("DSAppSettings")("sqlconnString") End Get End Property Private ReadOnly Property Connection() As SqlConnection Get Dim ConnectionToFetch As New SqlConnection(ConnectionString) ConnectionToFetch.Open() Return ConnectionToFetch End Get End Property Public Function GetData(ByVal Expression As String) As DataSet Dim SelectQry = Expression Dim SampleSource As New DataSet Dim SampleDataAdapter As New SqlDataAdapter(SelectQry, ConnectionString) SampleDataAdapter.Fill(SampleSource) Return SampleSource End Function Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmitComment.Click oBlog = New Blog If Page.IsValid Then oBlog.iArticleID = Request.QueryString("ArticleID") If txtAuthor.Text = String.Empty Then oBlog.sAuthor = "Unknown Author" Else oBlog.sAuthor = txtAuthor.Text End If oBlog.sComment = txtComment.Text oBlog.dtDateAdded = Now() oBlogDAO.InsertComments(oBlog, iAddUpdateIn:=0) txtComment.Text = String.Empty dlComments.DataSource = GetData("select * from BlogComments where ArticleID =" & Request.QueryString("ArticleID") & "Order by DateAdded DESC") dlComments.DataBind() Else Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alertMe();", True) End If End Sub Public Overloads Sub databind() dadapter = New SqlDataAdapter("select * from BlogComments where ArticleID =" & Request.QueryString("ArticleID") & "Order by DateAdded DESC", connstring) dset = New DataSet() adsource = New PagedDataSource() dadapter.Fill(dset) adsource.DataSource = dset.Tables(0).DefaultView adsource.PageSize = 5 adsource.AllowPaging = True adsource.CurrentPageIndex = pos btnfirst.Enabled = Not adsource.IsFirstPage btnprevious.Enabled = Not adsource.IsFirstPage btnlast.Enabled = Not adsource.IsLastPage btnnext.Enabled = Not adsource.IsLastPage dlComments.DataSource = adsource dlComments.DataBind() End Sub Protected Sub btnfirst_Click(ByVal sender As Object, ByVal e As EventArgs) pos = 0 databind() End Sub Protected Sub btnprevious_Click(ByVal sender As Object, ByVal e As EventArgs) pos = CInt(Me.ViewState("vs")) pos -= 1 Me.ViewState("vs") = pos databind() End Sub Protected Sub btnnext_Click(ByVal sender As Object, ByVal e As EventArgs) pos = CInt(Me.ViewState("vs")) pos += 1 Me.ViewState("vs") = pos databind() End Sub Protected Sub btnlast_Click(ByVal sender As Object, ByVal e As EventArgs) pos = adsource.PageCount - 1 databind() End Sub End Class