2012-07-31 73 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

相關問題