我有一个listview
与dropdownlist
(医生)的任命。
我有3页为3位不同的医生。当我列出第一个医生姓名时,我会做下一页(我在第2页,医生1),我将dropdownlist
选择更改为医生2.
我原本希望在第1页看医生2.现在我在医生2,但第2页。
对如何重置列表视图的分页有任何想法?
这是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>
这是我在后面的page_load代码中添加的代码。 我们如何捕获此事件发生DropDownList1_SelectedIndexChanged(object sender,EventArgs e)?
if (IsPostBack && indexChanged) <== I need to know how to trap the
DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DataPager pgr = ListView1.FindControl("DataPager1") as DataPager;
if (pgr != null && ListView1.Items.Count != pgr.TotalRowCount)
{
pgr.SetPageProperties(0, pgr.MaximumRows, false);
bIndexDdlChanged = false;
}
}
答案 0 :(得分:2)
以下是我解决此问题的方法:
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);
}