السلام عليكم ورحمة الله وبركاته
هديتى لكم عمل paging next , previous ,first and last in datalist
فى حدث page load نضيف
If Not Page.IsPostBack() Then
intPageSize.Text = "4"
intCurrIndex.Text = "0"
==ونكتب جملة الselect كالمعتاد وجمل اتصال وdataset==
If Not Page.IsPostBack() Then
objDA.Fill(objDS)
intRecordCount.Text = CStr(objDS.Tables(0).Rows.Count)
objDS = Nothing
objDS = New DataSet()
End If
objDA.Fill(objDS, CInt(intCurrIndex.Text), CInt(intPageSize.Text), "sales")
' objDA.Fill(objDS, CInt(intCurrIndex.Text), CInt(intPageSize.Text), "religion")
dList.DataSource = objDS.Tables(0).DefaultView
dList.DataBind()
objConn.Close()
PrintStatus()
======next ,previous .....======
Public Sub ShowFirst(ByVal s As Object, ByVal e As EventArgs)
intCurrIndex.Text = "0"
DataBind()
End Sub
Public Sub ShowPrevious(ByVal s As Object, ByVal e As EventArgs)
intCurrIndex.Text = CStr(CInt(intCurrIndex.Text) - CInt(intPageSize.Text))
If CInt(intCurrIndex.Text) < 0 Then
intCurrIndex.Text = "0"
End If
DataBind()
End Sub
Public Sub ShowNext(ByVal s As Object, ByVal e As EventArgs)
If CInt(intCurrIndex.Text) + 1 < CInt(intRecordCount.Text) Then
intCurrIndex.Text = CStr(CInt(intCurrIndex.Text) + CInt(intPageSize.Text))
End If
DataBind()
End Sub
Public Sub ShowLast(ByVal s As Object, ByVal e As EventArgs)
Dim tmpInt As Integer
tmpInt = CInt(intRecordCount.Text) Mod CInt(intPageSize.Text)
If tmpInt > 0 Then
intCurrIndex.Text = CStr(CInt(intRecordCount.Text) - tmpInt)
Else
intCurrIndex.Text = CStr(CInt(intRecordCount.Text) - CInt(intPageSize.Text))
End If
DataBind()
End Sub
==view sum pages==
Private Sub PrintStatus()
lblStatus.Text = "Total Records:<b>" & intRecordCount.Text
lblStatus.Text += "</b> - Showing Page:<b> "
lblStatus.Text += CStr(CInt(CInt(intCurrIndex.Text) / CInt(intPageSize.Text) + 1))
lblStatus.Text += "</b> of <b>"
If (CInt(intRecordCount.Text) Mod CInt(intPageSize.Text)) > 0 Then
lblStatus.Text += CStr(CInt(CInt(intRecordCount.Text) / CInt(intPageSize.Text) + 1))
Else
lblStatus.Text += CStr(CInt(intRecordCount.Text) / CInt(intPageSize.Text))
End If
lblStatus.Text += "</b>"
End Sub
=== وبالdatalist جمل ال item template كالتالى ====
<ItemTemplate>
<tr style="background-color:#f5f5dc">
<td><%#DataBinder.Eval(Container.DataItem, "column1")%></td>
<td><%# DataBinder.Eval(Container.DataItem, "column2") %></td>
<td><%#DataBinder.Eval(Container.DataItem, "column2")%></td>
</tr>
</ItemTemplate>
== next ,previous links ==
<a href="datalistpaging.aspx#this"
ID="hrefFirst"
onserverclick="ShowFirst"
runat="server"><b><<</b></a>
<a href="datalistpaging.aspx#this"
ID="hrefPrevious"
onserverclick="ShowPrevious"
runat="server"><b><</b></a>
<a href="datalistpaging.aspx#this"
ID="hrefNext"
onserverclick="ShowNext"
runat="server"><b>></b></a>
<a href="datalistpaging.aspx#this"
ID="hrefLast"
onserverclick="ShowLast"
runat="server"><b>>></b></a>
==lable to view count pages==
<asp:label ID="intCurrIndex"
Visible="False"
Runat="server" />
<asp:label ID="intPageSize"
Visible="False"
Runat="server" />
<asp:label ID="intRecordCount"
Visible="False"
Runat="server" />
لاتنسونى بالدعــــــــــــــــــــــاء
