<%@ Control Language="VB" AutoEventWireup="false" CodeFile="RepeaterWithPagingl.ascx.vb" Inherits="WebApplication1_RepeaterWithPagingl" %>
<div>
<asp:Label ID="countR" runat="server"></asp:Label>
<asp:HiddenField id="hdnno" runat="server"/>
<asp:Repeater ID="Employee01" runat="server" >
<HeaderTemplate>
<table>
<tr>
<td>
ID
</td>
<td>
Name
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table>
<tr>
<td>
<asp:Label ID="EmID" runat="server"
Text=' <%#Eval("ID") %>'></asp:Label>
</td>
<td>
<asp:Label ID="EmpName" runat="server"
Text='<%#Eval("FullName") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
<table>
<tr>
<td><asp:LinkButton ID="Prv" runat="server" Text="Prvious"></asp:LinkButton></td>
<td><asp:LinkButton ID="LinkButton1"
runat="server" Text="Next"></asp:LinkButton></td>
</tr>
</table>
</div>
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Server side code
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Imports System.Data.SqlClient
Imports System.Data
Imports System.Web.UI.WebControls
Partial Class WebApplication1_RepeaterWithPagingl
Inherits System.Web.UI.UserControl
Dim conn As New SqlConnection("Data
Source=.\SQLEXPRESS;AttachDbFilename=C:\PIS.mdf;Integrated
Security=True;Connect Timeout=30;User Instance=True")
Dim rowCnt As Integer = 0
Public Shared currPage As Integer = 0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
If Not IsPostBack Then
hdnno.Value = "0"
BindData("-2")
End If
End Sub
Public Sub BindData(ByVal pag As String)
Dim str As String = "select * from Users"
Dim cmd As New SqlCommand(str, conn)
Dim cmdAdp As New SqlDataAdapter(cmd)
Dim DataSet As New DataSet
cmdAdp.Fill(DataSet)
rowCnt = DataSet.Tables(0).Rows.Count
Dim pagData As New PagedDataSource
pagData.DataSource = DataSet.Tables(0).DefaultView
pagData.AllowPaging = True
pagData.PageSize = 2
pagData.CurrentPageIndex = currPage
Dim NoOfPage As Integer = rowCnt / pagData.PageSize
If currPage < 1 Then
Prv.Enabled = False
End If
If currPage > 0 Then
Prv.Enabled = True
End If
If NoOfPage > currPage Then
LinkButton1.Enabled = True
End If
If NoOfPage = (currPage + 1) Then
LinkButton1.Enabled = False
End If
Employee01.DataSource = pagData
Employee01.DataBind()
End Sub
/////////
This is the code for Prvious Button
\\\\\\\\
Protected Sub Prv_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Prv.Click
If hdnno.Value <> "" Then
hdnno.Value = Convert.ToString(CInt(hdnno.Value) - 1)
Else
hdnno.Value = "1"
End If
currPage = currPage - 1
countR.Text = currPage
BindData("-9")
End Sub
\\\\\\\\
This is the Code for next Button
////////
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles LinkButton1.Click
If hdnno.Value <> "" Then
hdnno.Value = Convert.ToString(CInt(hdnno.Value) + 1)
Else
hdnno.Value = "1"
End If
currPage = currPage + 1
countR.Text = currPage
BindData("2")
End Sub
End Class
<div>
<asp:Label ID="countR" runat="server"></asp:Label>
<asp:HiddenField id="hdnno" runat="server"/>
<asp:Repeater ID="Employee01" runat="server" >
<HeaderTemplate>
<table>
<tr>
<td>
ID
</td>
<td>
Name
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table>
<tr>
<td>
<asp:Label ID="EmID" runat="server"
Text=' <%#Eval("ID") %>'></asp:Label>
</td>
<td>
<asp:Label ID="EmpName" runat="server"
Text='<%#Eval("FullName") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
<table>
<tr>
<td><asp:LinkButton ID="Prv" runat="server" Text="Prvious"></asp:LinkButton></td>
<td><asp:LinkButton ID="LinkButton1"
runat="server" Text="Next"></asp:LinkButton></td>
</tr>
</table>
</div>
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Server side code
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Imports System.Data.SqlClient
Imports System.Data
Imports System.Web.UI.WebControls
Partial Class WebApplication1_RepeaterWithPagingl
Inherits System.Web.UI.UserControl
Dim conn As New SqlConnection("Data
Source=.\SQLEXPRESS;AttachDbFilename=C:\PIS.mdf;Integrated
Security=True;Connect Timeout=30;User Instance=True")
Dim rowCnt As Integer = 0
Public Shared currPage As Integer = 0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
If Not IsPostBack Then
hdnno.Value = "0"
BindData("-2")
End If
End Sub
Public Sub BindData(ByVal pag As String)
Dim str As String = "select * from Users"
Dim cmd As New SqlCommand(str, conn)
Dim cmdAdp As New SqlDataAdapter(cmd)
Dim DataSet As New DataSet
cmdAdp.Fill(DataSet)
rowCnt = DataSet.Tables(0).Rows.Count
Dim pagData As New PagedDataSource
pagData.DataSource = DataSet.Tables(0).DefaultView
pagData.AllowPaging = True
pagData.PageSize = 2
pagData.CurrentPageIndex = currPage
Dim NoOfPage As Integer = rowCnt / pagData.PageSize
If currPage < 1 Then
Prv.Enabled = False
End If
If currPage > 0 Then
Prv.Enabled = True
End If
If NoOfPage > currPage Then
LinkButton1.Enabled = True
End If
If NoOfPage = (currPage + 1) Then
LinkButton1.Enabled = False
End If
Employee01.DataSource = pagData
Employee01.DataBind()
End Sub
/////////
This is the code for Prvious Button
\\\\\\\\
Protected Sub Prv_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Prv.Click
If hdnno.Value <> "" Then
hdnno.Value = Convert.ToString(CInt(hdnno.Value) - 1)
Else
hdnno.Value = "1"
End If
currPage = currPage - 1
countR.Text = currPage
BindData("-9")
End Sub
\\\\\\\\
This is the Code for next Button
////////
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles LinkButton1.Click
If hdnno.Value <> "" Then
hdnno.Value = Convert.ToString(CInt(hdnno.Value) + 1)
Else
hdnno.Value = "1"
End If
currPage = currPage + 1
countR.Text = currPage
BindData("2")
End Sub
End Class
No comments:
Post a Comment