C# 在ListView C中重置页面#

C# 在ListView C中重置页面#,c#,asp.net,listview,C#,Asp.net,Listview,我有一个任命列表视图,带有一个下拉列表(医生) 我有3页,分别给3位不同的医生。当我列出第一个医生的名字并进入下一页时(对于医生1,我在第2页),我将dropdownlist选择更改为医生2 我原以为会在《医生2》的第一页上。现在我在看医生2,但第2页 您知道如何重置listview的分页吗 以下是aspx代码: <asp:LinqDataSource ID="LinqDataSource2" runat="server"></asp:LinqDataSource>

我有一个任命
列表视图
,带有一个
下拉列表
(医生)

我有3页,分别给3位不同的医生。当我列出第一个医生的名字并进入下一页时(对于医生1,我在第2页),我将
dropdownlist
选择更改为医生2

我原以为会在《医生2》的第一页上。现在我在看医生2,但第2页

您知道如何重置listview的分页吗

以下是aspx代码:

 <asp:LinqDataSource ID="LinqDataSource2" runat="server"></asp:LinqDataSource>
 <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="AptDataContext" 
     EnableUpdate="True" EntityTypeName="" TableName="Appointement" 
     Where="IsAvailable = True && dateApt >= DateTime.Now && doctorId = Doctor.Id &&
            doctorid = 1"> 

    <WhereParameters>
       <asp:ControlParameter 
           Name="doctor_name" 
           ControlID="DropDownList1" 
           PropertyName="SelectedValue"
           Type="String" />
    </WhereParameters>
 </asp:LinqDataSource>

 <div class="center">
    <asp:Label ID="lblDocName" runat="server" Text="Choose a doctor name"> </asp:Label>

    <div class="value-right"> 
       <asp:DropDownList ID="DropDownList1" runat="server" Width="180px" AutoPostBack="true" 
          OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
          DataTextField="Doctor_name"  >
       </asp:DropDownList> 
    </div>  
 </div>
 <br/><br/>
 <asp:Label ID="lblChooseApt" runat="server" Text="Choose a date"> </asp:Label>
 <br/>
 <asp:ListView ID="ListView1" runat="server" DataKeyNames="rdvId" DataSourceID="LinqDataSource1" 
      InsertItemPosition="LastItem" Autopostback="true" 
      OnPagePropertiesChanged="ListView1_PagePropertiesChanged"  >
    <AlternatingItemTemplate>
    <tr style="">
        <td>
             <asp:Label ID="doctorNameLabel" runat="server" 
                  Text='<%# Eval("Doctor.Doctor_Name") %>' />
        </td>
        <td>
            <asp:Label ID="dateAptLabel" runat="server" Text='<%# Eval("dateApt", 
                       "{0:dd/MM/yyyy}") %>' />
        </td>
        <td>
            <asp:Label ID="houreAptLabel" runat="server" Text='<%# Eval("houreApt"
                     , @"{0:hh\:mm}") %>' />
        </td>
        <td>
           <asp:CheckBox id="MyCheckBox" runat="server"
                value='<%# Eval("aptId") %>'
                AutoPostBack="true"
                OnCheckedChanged="Check_Clicked" />
        </td>

        <asp:HiddenField ID="doctorIdLabel" runat="server" Value='<%# Eval("doctorId") %>' />
    </tr>
    </AlternatingItemTemplate>
    <tr runat="server">
        <td runat="server" style="">
            <asp:DataPager ID="DataPager1" runat="server" Autopostback="true" >
                 <Fields>
                     <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                       ShowLastPageButton="True" />
                 </Fields>
            </asp:DataPager>
        </td>
     </tr>




这是我放在页面中的代码,后面是加载代码。 我们如何阻止此事件发生DropDownList 1\u SelectedIndexChanged(对象发送方,EventArgs e)


if(IsPostBack&&indexChanged)以下是我解决此问题的方法:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    int indexDdl = DropDownList1.SelectedIndex;
    indexDdl++;
    Session["doctorId"] = indexDdl;

    if (IsPostBack)                                                          <==new code added
    {
        DataPager pgr = ListView1.FindControl("DataPager1") as DataPager;    <==new code added
        if (pgr != null && ListView1.Items.Count != pgr.TotalRowCount)       <==new code added
        {
            pgr.SetPageProperties(0, pgr.MaximumRows, false);                <==new code added
        }
    }

    ListAppointement(indexDdl);
}
protectedvoid DropDownList1\u SelectedIndexChanged(对象发送方,事件参数e)
{
int indexDdl=DropDownList1.SelectedIndex;
indexDdl++;
会话[“doctorId”]=indexDdl;

如果(IsPostBack)检查@Deependra Mehrotra我检查了您提供的链接,我的问题是我不知道如何在asp:Datapager内的.aspx页面中设置MyPager。您知道吗?DataPager1.SelectedIndex(SelectedPage)=0???@Marciano.Andrade您知道如何指示此事件是否发生DropDownList1\u SelectedIndexChanged(object sender,EventArgs e)每次我进入时,我都需要一个指示器,以便我可以在页面加载中使用此指示器来知道是否需要重置页面
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    int indexDdl = DropDownList1.SelectedIndex;
    indexDdl++;
    Session["doctorId"] = indexDdl;

    if (IsPostBack)                                                          <==new code added
    {
        DataPager pgr = ListView1.FindControl("DataPager1") as DataPager;    <==new code added
        if (pgr != null && ListView1.Items.Count != pgr.TotalRowCount)       <==new code added
        {
            pgr.SetPageProperties(0, pgr.MaximumRows, false);                <==new code added
        }
    }

    ListAppointement(indexDdl);
}