【发布时间】:2011-10-06 13:19:49
【问题描述】:
我无法更改 gridview 的页面索引。 OnPageIndexChanging 的服务器方法根本没有被触发。我不知道我在这里做错了什么。
这是我的网格视图
<asp:GridView ID="VideoCommentsGrid" runat="server"
OnRowDataBound="VideoCommentsGrid_RowDataBound"
OnPageIndexChanging="VideoCommentsGrid_PageIndexChanging" allowpaging="true"
CssClass="tables"
EmptyDataText="<div class='notice show bottom'>No Comments found.</div>"
AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField HeaderStyle-HorizontalAlign="center" HeaderStyle-Width="70" ItemStyle-HorizontalAlign="center">
<HeaderTemplate>
Approve
<br />
<input id="ChkAllApprovedItems" type="checkbox" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkApproval" Checked='<%#Eval("IsApproved").ToString()=="1"?true:false %>' runat="server" />
<asp:Label ID="lblCommentID" runat="server" Text='<%#Eval("CommentId") %>' CssClass="hide"/>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderStyle-HorizontalAlign="center" HeaderStyle-Width="70" ItemStyle-HorizontalAlign="center">
<HeaderTemplate>
Reject
<br />
<input id="ChkAllRejectedItems" type="checkbox" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkReject" Checked='<%#Eval("IsRejected").ToString()=="1"?true:false %>' runat="server" />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="User Name" HeaderStyle-Width="70" >
<ItemTemplate>
<asp:Label ID="lblUserName" runat="server" Text='<%#Eval("FirstName")%>'> </asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="150" />
<ItemStyle HorizontalAlign="Left" CssClass="wordWrap" Width="150" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Comments" HeaderStyle-Width="70" >
<ItemTemplate>
<asp:Label ID="lblComment" runat="server" Text='<%#Eval("VideoComment") %>' />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="150" />
<ItemStyle HorizontalAlign="Left" CssClass="wordWrap" Width="150" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Comment Time* ">
<ItemTemplate>
<asp:Label ID="lblCommentDate" runat="server" Text='<%#(Eval("CommentCreatedDate"))%>'> </asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" Width="80" />
<ItemStyle HorizontalAlign="Center" Width="80" />
</asp:TemplateField>
</Columns>
<HeaderStyle Height="30" />
<PagerStyle HorizontalAlign="Center" CssClass="footer" />
<AlternatingRowStyle CssClass="odd" />
</asp:GridView>
我的服务器端代码如下,
protected void Page_Load(object sender, EventArgs e)
{
LoadCommentsGridView(VideoCommentsGrid.PageIndex);
}
protected void VideoCommentsGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (!e.Row.RowType.Equals(DataControlRowType.DataRow)) return;
}
protected void VideoCommentsGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
VideoCommentsGrid.PageIndex = e.NewPageIndex;
LoadCommentsGridView(VideoCommentsGrid.PageIndex);
hidCheckedValue.Value = string.Empty;
}
protected void LoadCommentsGridView(int PageIndex)
{
SetPageIndex(PageIndex);
LoadDefaultGrid();
}
private void LoadDefaultGrid()
{
VideoCommentsGrid.PageSize = CurrentSchoolDetails.PageViewCount;
IList<Comment> allComments = CommentRepository.GetAllCommentsByVideoID(VideoID);
BindDataControls.BindGridView(VideoCommentsGrid, allComments);
}
请帮帮我, 谢谢。
【问题讨论】:
-
您的
SetPageIndex()是做什么的?以编程方式设置页面索引? -
@Ates - 是的,我正在以编程方式设置页面索引
-
好吧,我找到了这个GridView.PageIndexChanging Event,上面写着
This event is not raised when you programmatically set the PageIndex property.。实际上你确实以编程方式设置了PageIndex 属性。 -
谢谢。让我进行必要的更改并再次测试。
-
好的,如果它有效,请告诉我。我认为作为社区 wiki 答案可能对其他人有好处。
标签: asp.net gridview aspxgridview