Tips & Tricks for ASP.NET - C#

Google site Search
Paging using Datalist

Imports System.Data.SqlClient
Imports System.Data


Partial Class TagResultsTnPages
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim myCON As New SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim mySql, sw, swtmp As String
        Dim totrows As Integer
        Dim mySqlCommand As New SqlCommand
        Dim myDA As SqlDataAdapter
        Dim myDS As New DataSet
        Dim myPGDS As New PagedDataSource
        Dim curpage, i As Integer
        Dim hlPageNo As HyperLink
        Dim myrow As TableRow
        Dim mycell As TableCell

        swtmp = Request.QueryString("swtmp")
        lblSW.Text = """ & swtmp & "" "

        sw = "%" & swtmp & "%"

        mySql = "SearchImages "
        mySqlCommand.CommandText = mySql
        mySqlCommand.CommandType = CommandType.StoredProcedure
        mySqlCommand.Parameters.Add("@sw", SqlDbType.VarChar, 100).Value = sw
        mySqlCommand.Connection = myCON


        myDA = New SqlDataAdapter
        myDA.SelectCommand = mySqlCommand
        myDA.Fill(myDS, "mytable")

        totrows = myDS.Tables("mytable").Rows.Count
        If totrows = 0 Then
            lblNoSearch.Text = "Sorry no results found for your search query"
        End If

        myPGDS.DataSource = myDS.Tables("mytable").DefaultView

        myPGDS.AllowPaging = True
        myPGDS.PageSize = 9

        myrow = New TableRow

        For i = 1 To myPGDS.PageCount
            hlPageNo = New HyperLink
            hlPageNo.Text = i
            hlPageNo.NavigateUrl = "tagresultstnpages.aspx?Page=" & i & "&swtmp=" & swtmp

            hlPageNo.Font.Name = "arial"


            If Request.QueryString("page") = i Then
                hlPageNo.ForeColor = Drawing.Color.Maroon
                hlPageNo.Font.Underline = False
            Else
                hlPageNo.ForeColor = Drawing.Color.DodgerBlue
            End If

            hlPageNo.Font.Bold = True
            hlPageNo.Font.Size = 10
            mycell = New TableCell

            mycell.Controls.Add(hlPageNo)
            myrow.Cells.Add(mycell)
            pageno.Rows.Add(myrow)
        Next


        If Not IsNothing(Request.QueryString("Page")) Then
            curpage = Convert.ToInt32(Request.QueryString("Page"))
        Else
            curpage = 1
        End If
        myPGDS.CurrentPageIndex = curpage - 1

        lblCurrpage.Text = "Page: " & curpage.ToString() & " of " & myPGDS.PageCount

        If Not myPGDS.IsFirstPage Then
            lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + _
                                           "?Page=" + CStr(curpage - 1) & "&swtmp=" & Request.QueryString("swtmp").ToString
        End If

        If Not myPGDS.IsLastPage Then
            lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + _
                                           "?Page=" + CStr(curpage + 1) & "&swtmp=" & Request.QueryString("swtmp").ToString
        End If

        DataList1.DataSource = myPGDS
        DataList1.DataBind()

        myCON.Close()

    End Sub

 
End Class

 

 


html

 


    <asp:DataList ID="DataList1" runat="server" Style="z-index: 102;" RepeatColumns="3" RepeatDirection="Horizontal" Width="1px" Height="156px">
        <ItemTemplate>
        <table><tr><td>
        <table border="1" style=" border-collapse:collapse;border-style:solid; border-color:#dddddd; " cellspacing="1"><tr><td>
              
        <table>
       
          
        <tr>
        <td>&nbsp;&nbsp;&nbsp;</td>
        <td style="font-family:Arial;font-size:small; font-weight:bold "><%#DataBinder.Eval(Container.DataItem, "title").ToString.Trim%></td>
        <td>&nbsp;&nbsp;&nbsp;</td>
        </tr>
       
        <tr>
        <td>&nbsp;&nbsp;&nbsp;</td>
        <td style="width:200px; height:150px;"><a style="border-width:0px;" href="Snaps.aspx?imageid=<%#DataBinder.Eval(Container.DataItem, "ID")%>&albumid=<%#DataBinder.Eval(Container.DataItem, "albumid")%>"><img style="max-width:200px; border-width:0px;"  alt="Click for Enlarged view" src="thumbnails.aspx?imageid=<%#DataBinder.Eval(Container.DataItem, "ID")%>&h=150" /></a></td>
        <td>&nbsp;&nbsp;&nbsp;</td>
        </tr>
       
        <tr>
        <td>&nbsp;&nbsp;&nbsp;</td>
    <td valign="middle"  style=" color:Gray;font-family:Arial;font-size:xx-small ;">
   
    <table><tr><td></td><td><a href="Snaps.aspx?imageid=<%#DataBinder.Eval(Container.DataItem, "ID")%>&albumid=<%#DataBinder.Eval(Container.DataItem, "albumid")%>"><img src="images/icoEnlarge.gif" alt="Enlarge" style="border:0px" /></a></td></tr></table>
   
    </td>
        <td>&nbsp;&nbsp;&nbsp;</td>
        </tr>
             
       
       
        </table>
       
        </td></tr></table>
       
        </td>
        </tr>
        <tr><td>&nbsp;</td>
        </tr>
        </table>
    
        </ItemTemplate>
       
    </asp:DataList>



Arvixe offers ASP.net hosting that's good for testing plugins. Here is a good arvixe review if you want to know more.

Comments
ffsd Says:-
“ sdfsdfd ”
 
 
Write Comments
Name  
Email    
Comments  

Other Titles