【发布时间】:2012-07-31 09:36:30
【问题描述】:
当我在 datapager 中更改页面时,它会导致完全回发,即使 datapager 工作非常异常,也不知道是什么原因。通过异常,我的意思是有时数据有时不显示,
以下是我在 c# 中的代码
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindListView();
}
}
protected void StudentListView_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
BindListView();
}
private void BindListView()
{
StudentListView.DataSource = StudentDataSource;
StudentListView.DataBind();
}
protected void StudentDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
e.Arguments.MaximumRows = StudentListDataPager.MaximumRows;
e.Arguments.StartRowIndex = StudentListDataPager.StartRowIndex;
}
以下是我的标记
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<ContentTemplate> <
<asp:DropDownList runat="server" ID="BatchDropDownList" AutoPostBack="True">
<asp:ListItem Text="Batch 1" Value="1" Selected="True" />
<asp:ListItem Text="Batch 2" Value="2" />
</asp:DropDownList>
<asp:ListView ID="StudentListView" runat="server"
ItemPlaceholderID="ListViewContent"
EnableViewState="false"
onpagepropertieschanging="StudentListView_PagePropertiesChanging">
<LayoutTemplate>
<table style="width:100%">
<thead>
<tr>
<th class="align-left"><strong>Name</strong></th>
<th class="align-left"><strong>MobNo</strong></th>
</tr>
</thead>
<tbody runat="server" id="ListViewContent">
</tbody>
<tfoot>
<tr>
<td colspan="3">
</td>
</tr>
</tfoot>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td style="width:70%;"><%# Eval("FirstName") %> <%# Eval("LastName") %></td>
<td style="width:30%;"><%# Eval("MobNo") %></td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:DataPager ID="StudentListDataPager" runat="server" PageSize="5" PagedControlID="StudentListView">
<Fields>
<asp:NumericPagerField />
</Fields>
</asp:DataPager>
<asp:ObjectDataSource ID="StudentDataSource" runat="server"
SelectMethod="GetStudentListBatchWise" SelectCountMethod="StudentCount"
TypeName="SCERPCommonUtil.Student" EnablePaging="True"
onselecting="StudentDataSource_Selecting">
<SelectParameters>
<asp:ControlParameter Name="batchId" ControlID="BatchDropDownList" PropertyName="SelectedValue" />
</SelectParameters>
</asp:ObjectDataSource>
</ContentTemplate>
</asp:UpdatePanel>
如果我犯了任何错误,请告诉我。
附: :请不要指出任何 stackoverflow 问题,因为我已经阅读了所有这些问题,并且没有一个特定于我的要求,
我面临的最重要的问题是,即使将datapager 放入updatepanel 内,也会发生同样的事情。
【问题讨论】:
-
亲爱的,您已将 updatemode 指定为有条件的。您是否在更新面板中提到了回发触发器????
-
好的 - 在
StudentListView_PagePropertiesChanging()事件中使用StudentListDataPager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);,数据分页器现在可以正常工作,但更新面板的问题仍然是守护进程,这会导致完全回发,并且我丢失了所有我的 javascript 本地变量.
标签: c# asp.net updatepanel objectdatasource datapager