2012-07-31 56 views
1

当我在datapager中更改页面时,会导致完全回发,即使datapager工作异常,idont知道是什么原因。通过abnormaaly我的意思是某个数据显示的某个时候犯规,
以下是个我的代码在C#listview,datapager,objectdatasource不能在updatepanel中工作

 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") %>&nbsp<%# 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> 

请告诉我,如果我犯错误。

P.S. :请不要点我任何计算器的问题。我读过所有的人,并没有专门针对我的要求,

我面临的最重要的问题是,DataPager的是充分的回发,即使把datapagerupdatepanel相同事情发生。

+0

亲爱的你已经指定updatemode为条件。你有提到回发触发到你的更新面板吗? – 2012-07-31 10:22:08

+0

好了 - 用'StudentListDataPager.SetPageProperties(e.StartRowIndex,e.MaximumRows,false);'在'StudentListView_PagePropertiesChanging()'事件中,数据包现在可以正常工作,但仍然存在更新面板的问题,因为守护进程会导致完全回发,我失去了我所有的javascript本地变量。 – j4m4l 2012-07-31 11:01:40

回答

-1

我想通了 - 柜面有人来找 -

我使用<form runat="server">...<form>标签,里面所有这列表视图,DataPager的代码存在。当我分配了独特的id属性来形成标签,然后一切开始正常工作。
虽然我不明白这种行为的原因。

0

亲爱的你已经指定updatemode为conditional.But你已经提到了更新面板的任何触发器。 添加AsyncPostBackTrigger您更新面板

<asp:UpdatePanel runat="server" UpdateMode="Conditional"> 
<ContentTemplate> 
<Triggers> 
      <asp:AsyncPostBackTrigger ControlID="StudentListView" EventName="PagePropertiesChanging" /> 
</Triggers> 
<ContentTemplate> 
</asp:UpdatePanel> 

从MSDN: If the UpdateMode property is set to Conditional, and one of the following conditions occurs:

  1. 你明确地调用UpdatePanel控件的Update方法。
  2. 回发是由使用UpdatePanel控件的Triggers属性定义为触发器的控件引起的。在这种情况下,控件显式触发面板内容的更新。该控件可以在定义触发器的UpdatePanel控件的内部或外部。
  3. ChildrenAsTriggers属性设置为true,并且UpdatePanel控件的子控件导致回发。除非将其明确定义为触发器,否则嵌套UpdatePanel控件的子控件不会更新外部UpdatePanel控件。

更新答: 你为什么不提了DataSourceID属性,在列表视图???

<asp:ListView ID="StudentListView" runat="server" DataSourceID ="StudentDataSource" 

,并要绑定在你的代码的列表视图要绑定它作为数据源,这是不对的身后,

private void BindListView() 
{ 
    StudentListView.DataSource = StudentDataSource; //also it should be DataSourceID 
    StudentListView.DataBind(); 
} 

您使用对象的数据源,并在你的代码。将它绑定为数据源ID或简单提及listview的datasourceID属性,那么您不必在后面的代码中绑定它。

+0

'PagePropertiesChanging'事件与ListView相关联,而不是与DataPager相关,我也删除了UpdateMode并尝试过,但它仍然不能正常工作。 – j4m4l 2012-07-31 10:30:48

+0

对不起,我给了错误的ID来触发。你的代码工作正常,无需更新面板?检查它 – 2012-07-31 10:34:54

+0

对不起,但你建议不工作,它仍然给予全面回发。 – j4m4l 2012-07-31 10:35:43

相关问题