编辑:现在工作,见下文。
大家好,
我的 ASP.Net 3.5 应用程序有一点问题。我正在尝试让程序获取已单击的页码。我正在使用 ASP.Net 内置的 AllowPaging="True" 函数。没有代码就不一样了,所以这里是:
ASP.NET:
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="Vertical" Width="960px" AllowSorting="True"
EnableSortingAndPagingCallbacks="True" AllowPaging="True" PageSize="25" >
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
C#:
var fillTable = from ft in db.IncidentDatas
where ft.pUserID == Convert.ToInt32(ClientList.SelectedValue.ToString())
select new
{
Reference = ft.pRef.ToString(),
Date = ft.pIncidentDateTime.Value.Date.ToShortDateString(),
Time = ft.pIncidentDateTime.Value.TimeOfDay,
Premesis = ft.pPremises.ToString(),
Latitude = ft.pLat.ToString(),
Longitude = ft.pLong.ToString()
};
if (fillTable.Count() > 0)
{
GridView1.DataSource = fillTable;
GridView1.DataBind();
var IncidentDetails = fillTable.ToList();
for (int i = 0; i < IncidentDetails.Count(); i++)
{
int pageno = GridView1.PageIndex;
int pagenostart = pageno * 25;
if (i >= pagenostart && i < (pagenostart + 25))
{
//Processing
}
}
}
知道为什么 GridView1.PageIndex 总是 = 0 吗?问题是,网格视图的处理工作正常......它总是会转到正确的分页页面,但是当我尝试获取数字时它总是 0。帮助!