Scott M. said:
First, yes you are bringing all the data into the grid when you use
paging (unless you are using custom paging), you are only showing one
page of data at a time, but you are, in fact bringing all the data down
to the grid.
All of the Web Form controls (DataGrid included) persist their own state
between page requests via ViewState. ViewState is a hidden form field
that contains the entire page's state encoded and compressed into this
string. After you go and get the data on the first page call, ALL of the
data is placed into the ViewState hidden form field. On the next page
call, the data is taken out of ViewState and placed back into the various
controls that had the data in the first place. This is why you only need
to go to the data on the first page call.
If you are using the Custom Paging feature, you are going to be only
retrieving one page of data at a time and so in this circumstance you
would have to go back to the database on each page call to get the next
set of records.
I'm not using the Custom Paging Feature, but I am calling my BindData
procedure to get the data each time. The following procedure is linked to
my first/next/previous/last links and sets the CurrentPageIndex
accordingly. The last line calls the BindData procedure and it works fine.
But if what you say is true, I am doing a lot of extra work (and slowing
the page down, I would assume). The problem is that if I comment out the
BindData routine the Datagrid comes back exactly the same as it did before
post.
**********************************************************
Sub PagerButtonClick(sender As Object, e As EventArgs)
trace.warn("in PagerButtonClick")
'used by external paging UI
Dim arg As String = sender.CommandArgument
Dim oGrid = DataGrid1
Select arg
Case "next": 'The next Button was Clicked
If (oGrid.CurrentPageIndex < (oGrid.PageCount - 1)) Then
oGrid.CurrentPageIndex += 1
End If
Case "prev": 'The prev button was clicked
If (oGrid.CurrentPageIndex > 0) Then
oGrid.CurrentPageIndex -= 1
End If
Case "last": 'The Last Page button was clicked
oGrid.CurrentPageIndex = (oGrid.PageCount - 1)
Case Else: 'The First Page button was clicked
oGrid.CurrentPageIndex = Convert.ToInt32(arg)
End Select
'Now, bind the data!
' BindData(lastSortColumn)
End Sub
**************************************************************
Here is my DataGrid
*********************************************************
<asp
ataGrid AllowPaging="true"
AllowCustomPaging="false"
PageSize="10"
PagerStyle-Visible="false"
Visible=false
AllowSorting="True"
AutoGenerateColumns="false"
CellPadding="3"
CellSpacing="0"
GridLines="Both" BorderColor="#666666"
ID="DataGrid1"
runat="server"
ShowFooter="false"
ShowHeader="true"
OnSortCommand="SortDataGrid"
BorderWidth="1"
style="margin:auto; width:700px">
<headerstyle HorizontalAlign="center" BackColor="#6ce0f7"
ForeColor="#3EA2BC" Font-Bold="true" />
<itemstyle BackColor="#F2F2F2" />
<alternatingitemstyle BackColor="#E5E5E5" />
<footerstyle HorizontalAlign="center" BackColor="#E8EBFD"
ForeColor="#3D3DB6" Font-Bold="true" />
<pagerstyle BackColor="white" />
<columns>
<asp:BoundColumn DataField="Applied"
ReadOnly="true"
Visible="True" ItemStyle-VerticalAlign="Top">
<itemstyle ForeColor="red" />
</asp:BoundColumn>
<asp:BoundColumn DataField="Rank"
HeaderText="Rank"
ReadOnly="true"
Visible="False" ItemStyle-VerticalAlign="Top"
SortExpression="Rank"> </asp:BoundColumn>
<asp:HyperLinkColumn DataTextField="JobTitle"
DataTextFormatString="{0}" DataNavigateUrlField="PositionID"
DataNavigateUrlFormatString="displayPositionOnly.aspx?PositionID={0}"
headertext="Job Title"
sortexpression="JobTitle" ItemStyle-VerticalAlign="Top"/>
<asp:BoundColumn DataField="Company"
HeaderText="Company"
ReadOnly="true"
Visible="True" ItemStyle-VerticalAlign="Top"
SortExpression="Company"/>
<asp:BoundColumn DataField="Location"
HeaderText="Location"
ReadOnly="true"
Visible="True" ItemStyle-VerticalAlign="Top"
SortExpression="Location"/>
<asp:BoundColumn DataField="Posted"
HeaderText="Date"
ReadOnly="true"
Visible="True" ItemStyle-VerticalAlign="Top"
SortExpression="DatePosted">
<itemstyle CssClass="datedisplay" />
</asp:BoundColumn>
<asp:BoundColumn DataField="lastUpdated"
HeaderText="Last Updated"
ReadOnly="true"
Visible="false" ItemStyle-VerticalAlign="Top"
SortExpression="p.DateUpdated">
<itemstyle CssClass="datedisplay" />
</asp:BoundColumn>
</columns>
</asp
ataGrid>
<asp
ataGrid AllowPaging="true"
AllowCustomPaging="false"
PageSize="4"
PagerStyle-Visible="false"
visible="false"
AllowSorting="True"
AutoGenerateColumns="false"
CellPadding="3"
CellSpacing="0"
GridLines="Both" BorderColor="#666666"
ID="DataGrid2"
runat="server"
ShowFooter="false"
ShowHeader="true"
OnSortCommand="SortDataGrid"
BorderWidth="1"
style="margin:auto;width:700px">
<HeaderStyle HorizontalAlign="center" BackColor="#6ce0f7"
ForeColor="#3EA2BC" Font-Bold="true" />
<ItemStyle BackColor="#F2F2F2" />
<AlternatingItemStyle BackColor="#E5E5E5" />
<FooterStyle HorizontalAlign="center" BackColor="#E8EBFD"
ForeColor="#3D3DB6" Font-Bold="true" />
<PagerStyle BackColor="white" />
<Columns>
<asp:BoundColumn DataField="Applied"
ReadOnly="true"
Visible="True" ItemStyle-VerticalAlign="Top">
<itemstyle ForeColor="red" />
</asp:BoundColumn>
<asp:BoundColumn DataField="Rank"
HeaderText="Rank"
ReadOnly="true"
Visible="False" ItemStyle-VerticalAlign="Top"
SortExpression="Rank">
</asp:BoundColumn>
<asp:TemplateColumn SortExpression="JobTitle"
ItemStyle-VerticalAlign="Top" HeaderText="Job Title">
<itemtemplate>
<asp:hyperlink text='<%# Container.DataItem("JobTitle")%>'
NavigateUrl='<%# "displayPositionOnly.aspx?PositionID=" &
Container.DataItem("PositionID") %>' runat="server" /><br>
<asp:label text='<%# Container.DataItem("JobDescription")%>'
runat="server" />...[<asp:hyperlink text='more' NavigateUrl='<%#
"displayPositionOnly.aspx?PositionID=" & Container.DataItem("PositionID")
%>' runat="server" />]
<br><asp:Label Text="Job Category: " style="font-weight:bold"
runat="server" /><asp:label text='<%# Container.DataItem("Category")%>'
runat="server" />
<br><asp:Label Text="Compensation: " style="font-weight:bold"
runat="server" /><asp:label text='<%# Container.DataItem("SalaryMin")%>'
runat="server" />
<asp:Label Text="- " style="font-weight:bold" runat="server"
/><asp:label text='<%# Container.DataItem("SalaryMax")%>' runat="server"
/>
</itemtemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Company"
HeaderText="Company"
ReadOnly="true"
Visible="True" ItemStyle-VerticalAlign="Top"
SortExpression="Company"/>
<asp:BoundColumn DataField="Location"
HeaderText="Location"
ReadOnly="true"
Visible="True" ItemStyle-VerticalAlign="Top"
SortExpression="Location"/>
<asp:BoundColumn DataField="Posted"
HeaderText="Date"
ReadOnly="true"
Visible="True" ItemStyle-VerticalAlign="Top"
SortExpression="DatePosted">
<Itemstyle CssClass="datedisplay" />
</asp:Boundcolumn>
<asp:BoundColumn DataField="lastUpdated"
HeaderText="Last Updated"
ReadOnly="true"
Visible="false" ItemStyle-VerticalAlign="Top"
SortExpression="p.DateUpdated">
<Itemstyle CssClass="datedisplay" />
</asp:Boundcolumn>
</Columns>
</asp
ataGrid>
************************************************************
Even if I change the CurrentPageIndex, is there something I need to do to
tell the page to reposition based on it?
Thanks,
Tom