T
Troy Winter
First off, I'm a newbie to ASP.NET and the paging on the first page I
have built is not working correctly. My dataset has ~1500 records and
I have set the PageSize to be 25 and PagerStyle-PageButtonCount to be
25. When there's more than 625 records, the "..."'s appear to
navigate to the next set of pages. The problem have encountered is
the next set of pages link back to the first set of pages. For
example, when I click on '30', I navigate back to page '6'. When I
click '37', I navigate to page '13' and so on. Does anyone have any
thoughts on what could be wrong? Here's some snips from my code.
- Troy
---------------------------------------------------------------------------
<%@ Page Language="VB" Debug="false" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import namespace="System.Data" %>
<script runat="server">
Dim Conn as New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
sub Page_Load(Sender as Object, e as EventArgs)
Dim strKey as string
BindData()
end sub
sub BindData ()
Dim ...
cmdPeople = new SqlCommand( "people_SearchPeople", Conn )
cmdPeople.CommandType = CommandType.StoredProcedure
cmdPeople.Parameters.Add( "@paramenter123", value123 )
try
Conn.Open
dadPeople = New SqlDataAdapter()
dadPeople.SelectCommand = cmdPeople
catch ex as Exception
response.write ("Error reading from db")
end try
dtsPeople = new DataSet()
dadPeople.Fill(dtsPeople, "People")
dgData.DataSource = dtsPeople
Try
dgData.CurrentPageIndex() = 0
dgData.DataBind()
Catch exc As Exception
'dgData.CurrentPageIndex() = dgData.PageCount - 1
dgData.CurrentPageIndex() = 0
dgData.DataBind()
End Try
'dtrPeople.close()
conn.close()
intRowCount = dtsPeople.Tables("People").Rows.Count
end sub
sub dgData_PageIndexChanged (Sender as Object, e as
DataGridPageChangedEventArgs)
dgData.CurrentPageIndex = e.NewPageIndex
dgData.DataBind()
end sub
</script>
<html>
....
....
<aspataGrid id="dgData" runat="server"
cellpadding = "0"
cellspacing = "1"
width = "100%"
ShowHeader = "False"
ShowFooter = "True"
Gridlines = "None"
FooterStyle = "link-gray-f10"
AutoGenerateColumns="False"
AllowPaging="True"
Font-Color="#356557"
Font-Name="Arial"
PageSize=25
PagerStyle-Mode=NumericPages
PagerStyle-HorizontalAlign = "Center"
PagerStyle-PageButtonCount = 25
PagerStyle-Font-Name="Arial"
PagerStyle-Font-Size="11pt"
OnPageIndexChanged="dgData_PageIndexChanged" >
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<tr class='bodytext-gray-f12'>
<td width="136" height="25" class='bodytext-gray-f12u'>
<A href='people_profile.asp?usrID=<%# Container.DataItem( "UsrID"
)%>'>
<%# Container.DataItem( "FirstName" )%>
<%# Container.DataItem( "LastName" )%>
</A>
</td>
<td width="195" ><%# Container.DataItem( "Employer" )%></td>
<td width="117" ><%# Container.DataItem( "CityName" )%></td>
<td width="117" ><%# Container.DataItem( "HomeTown" )%></td>
<td width="64" nowrap><%# Container.DataItem( "FmtCreateDate"
)%></td>
</tr>
<tr><td bgcolor='#CCCCCC' height='1' colspan='5'></td></tr>
</ItemTemplate>
<FooterTemplate>
<% response.write ( strBottomMessage ) %></font>
<!--end of footer-->
</FooterTemplate>
</asp:TemplateColumn>
</Columns>
</aspataGrid>
....
....
</html>
have built is not working correctly. My dataset has ~1500 records and
I have set the PageSize to be 25 and PagerStyle-PageButtonCount to be
25. When there's more than 625 records, the "..."'s appear to
navigate to the next set of pages. The problem have encountered is
the next set of pages link back to the first set of pages. For
example, when I click on '30', I navigate back to page '6'. When I
click '37', I navigate to page '13' and so on. Does anyone have any
thoughts on what could be wrong? Here's some snips from my code.
- Troy
---------------------------------------------------------------------------
<%@ Page Language="VB" Debug="false" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import namespace="System.Data" %>
<script runat="server">
Dim Conn as New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
sub Page_Load(Sender as Object, e as EventArgs)
Dim strKey as string
BindData()
end sub
sub BindData ()
Dim ...
cmdPeople = new SqlCommand( "people_SearchPeople", Conn )
cmdPeople.CommandType = CommandType.StoredProcedure
cmdPeople.Parameters.Add( "@paramenter123", value123 )
try
Conn.Open
dadPeople = New SqlDataAdapter()
dadPeople.SelectCommand = cmdPeople
catch ex as Exception
response.write ("Error reading from db")
end try
dtsPeople = new DataSet()
dadPeople.Fill(dtsPeople, "People")
dgData.DataSource = dtsPeople
Try
dgData.CurrentPageIndex() = 0
dgData.DataBind()
Catch exc As Exception
'dgData.CurrentPageIndex() = dgData.PageCount - 1
dgData.CurrentPageIndex() = 0
dgData.DataBind()
End Try
'dtrPeople.close()
conn.close()
intRowCount = dtsPeople.Tables("People").Rows.Count
end sub
sub dgData_PageIndexChanged (Sender as Object, e as
DataGridPageChangedEventArgs)
dgData.CurrentPageIndex = e.NewPageIndex
dgData.DataBind()
end sub
</script>
<html>
....
....
<aspataGrid id="dgData" runat="server"
cellpadding = "0"
cellspacing = "1"
width = "100%"
ShowHeader = "False"
ShowFooter = "True"
Gridlines = "None"
FooterStyle = "link-gray-f10"
AutoGenerateColumns="False"
AllowPaging="True"
Font-Color="#356557"
Font-Name="Arial"
PageSize=25
PagerStyle-Mode=NumericPages
PagerStyle-HorizontalAlign = "Center"
PagerStyle-PageButtonCount = 25
PagerStyle-Font-Name="Arial"
PagerStyle-Font-Size="11pt"
OnPageIndexChanged="dgData_PageIndexChanged" >
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<tr class='bodytext-gray-f12'>
<td width="136" height="25" class='bodytext-gray-f12u'>
<A href='people_profile.asp?usrID=<%# Container.DataItem( "UsrID"
)%>'>
<%# Container.DataItem( "FirstName" )%>
<%# Container.DataItem( "LastName" )%>
</A>
</td>
<td width="195" ><%# Container.DataItem( "Employer" )%></td>
<td width="117" ><%# Container.DataItem( "CityName" )%></td>
<td width="117" ><%# Container.DataItem( "HomeTown" )%></td>
<td width="64" nowrap><%# Container.DataItem( "FmtCreateDate"
)%></td>
</tr>
<tr><td bgcolor='#CCCCCC' height='1' colspan='5'></td></tr>
</ItemTemplate>
<FooterTemplate>
<% response.write ( strBottomMessage ) %></font>
<!--end of footer-->
</FooterTemplate>
</asp:TemplateColumn>
</Columns>
</aspataGrid>
....
....
</html>