2014-01-29 43 views
0

我有一個列表視圖和下拉列表選項。我第一次進入列表視圖時,我在列表視圖的底部使用了NEXT按鈕,它顯示的一切都很好。如果我將下拉列表更改爲另一個選項,它將首次顯示列表,但如果使用了NEXT按鈕,則不會刷新列表視圖。我正在使用AJAX和UpdatePanel。我看到listview正確填充(apt.Count()返回20條記錄)。任何想法可能是錯的?使用「下一步」按鈕後,listview不能正常刷新

我想我需要一個刷新或類似的東西可能是由於AJAX?

這裏是behing

private void ListApt(int iIndexDdl) 
{ 
    using (AptDataContext db = new AptDataContext()) 
    { 
     var apt = from Apt in db.Apt 
        join Doctor in db.Doctor on Apt.DoctorId equals Doctor.Id 

         where Apt.doctorId == iIndexDdl && Apt.IsAvailable == true && 
          Apt.dateApt >= DateTime.Now 
         select Apt 
         ; 

        ListView1.DataSourceID = null; 
        ListView1.DataSource = apt; 

        int numberOfRecords = apt.Count(); 
        if (numberOfRecords == 0) 
        { 
         lblMessage.Text = "No Appointement are available"; 
        } 

        ListView1.DataBind(); 
    }; 
} 

此處的代碼,其中該按鈕被在.aspx

<asp:DataPager ID="DataPager1" runat="server" > 
     <Fields> 
      <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
      ShowLastPageButton="True" /> 
     </Fields> 
    </asp:DataPager> 

回答

2
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
     <ContentTemplate> 
      <asp:ListView ID="ListViewPersons" runat="server" ItemPlaceholderID="ProductItem"> 
       <ItemTemplate> 
        <asp:Label runat="server" ID="LabelEmail" Text='<%# Eval("Email") %>'></asp:Label> 
        <asp:Label runat="server" ID="LabelName" Text='<%# Eval("Name") %>'></asp:Label> 
       </ItemTemplate> 
       <LayoutTemplate> 
        <asp:PlaceHolder runat="server" ID="ProductItem"></asp:PlaceHolder> 
       </LayoutTemplate> 
       <ItemSeparatorTemplate> 
        <hr /> 
       </ItemSeparatorTemplate> 
      </asp:ListView> 
      <asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListViewPersons" 
       onprerender="DataPager1_PreRender"> 
       <Fields> 
        <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" /> 
       </Fields> 
      </asp:DataPager> 
     </ContentTemplate> 
     <Triggers> 
      <asp:AsyncPostBackTrigger ControlID="ListViewPersons" /> 
     </Triggers> 
    </asp:UpdatePanel> 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!IsPostBack) 
     { 
      BindListView();     
     } 
    } 

    private void BindListView() 
    { 
     List<Person> persons = new List<Person>(); 
     for (int i = 0; i < 30; i++) 
     { 
      Person aPerson =new Person(); 
      aPerson.Email = "Email" + i.ToString(); 
      aPerson.Name = "Name" + i.ToString(); 
      persons.Add(aPerson); 
     } 

     ListViewPersons.DataSource = persons; 
     ListViewPersons.DataBind(); 
    }   

    public class Person 
    { 
     public string Name { get; set; } 
     public string Email { get; set; } 
    } 

    protected void DataPager1_PreRender(object sender, EventArgs e) 
    { 
     BindListView(); 
    } 

http://www.codeproject.com/Questions/513399/UpdateplusPanelplusdataplusisplusnotplusrefreshing

http://ajax.net-tutorials.com/controls/updatepanel-control/

+0

@Kaplan我在 user3127986

+0

我添加了這個但有時點擊按鈕後沒有什麼是刷新?任何想法?與AJAX無關? – user3127986

+0

這是您可以調整代碼的示例代碼。 – Kaptan

1
限定

1)你確定有更多的記錄要檢索嗎?也許你在列表的末尾。

2)在瀏覽器上使用調試模式。從下拉菜單中進行第一次刷新後,可能會出現錯誤,導致您的AJAX軟件無法播放。

3)注意更新面板中有哪些控件,以及哪些控件是更新觸發器。

你應該嚴厲地張貼你的標記代碼。問題很可能出現在您的標記或控件和事件的佈線中。

相關問題