我的ASPX页面中有一个搜索,一旦点击就会使用UpdatePanel显示结果,所以它显示的结果没有页面刷新。执行搜索的功能在此处:
public void onBtnClick() {
Conn = new SqlConnection(cString);
Conn.Open();
theGender = slcGender.SelectedItem.Text;
if (slcLocation.SelectedItem.Value == "") {
locVal = slcLocation.SelectedItem.Value;
lVal = "All Locations";
}
if (slcLocation.SelectedItem.Value != "") {
locVal = slcLocation.SelectedItem.Text;
lVal = slcLocation.SelectedItem.Text;
}
if (slcSpecialty.SelectedItem.Value == "") {
speVal = slcSpecialty.SelectedItem.Value;
sVal = "All Specialties";
}
if (slcSpecialty.SelectedItem.Value != "") {
speVal = slcSpecialty.SelectedItem.Text;
sVal = slcSpecialty.SelectedItem.Text;
}
if (slcGender.SelectedItem.Value == "") {
genVal = slcGender.SelectedItem.Value;
gVal = "Any Gender";
}
if (slcGender.SelectedItem.Value != "") {
genVal = theGender.Substring(0, 1);
gVal = slcGender.SelectedItem.Text;
}
sqlCode = "SELECT * FROM [HERE]"; --example query
/* EXECUTE AND DISPLAY THE DATA IN THE ASP PAGE */
using(SqlCommand command = new SqlCommand(sqlCode, Conn)) {
command.CommandType = CommandType.Text;
using (SqlDataReader reader = command.ExecuteReader()) {
if (reader.HasRows) {
rptContent.DataSource = reader;
rptContent.DataBind();
}
if (!reader.HasRows) {
dlo.InnerHtml = "NO RESULT";
}
int count = rptContent.Items.Count;
dlo.InnerHtml = "Your search in " + lVal + " by " + sVal + " and " + gVal + " returned "+count+" matches";
}
}
}
我的ASPX页面上有一个标签:
<asp:Label runat="server" Text="" ClientIDMode="Static" ID="dispSearch" style="float: left;"></asp:Label>
如何在执行搜索时向上面的标签显示“正在搜索...请稍候”消息,并在完成后显示“搜索已完成”消息?
我的UpdatePanel:
<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:UpdateProgress ID="TaskUpdateProgress" runat="server" DynamicLayout="False" AssociatedUpdatePanelID="UpdatePanel2" DisplayAfter="0">
<ProgressTemplate>
<asp:Image ImageUrl="theImages/loadanim_ff.gif" Width="319px" Height="3px" runat="server" ID="TaskLoadingImage"/>
</ProgressTemplate>
</asp:UpdateProgress>
<div style="width: 100%; color: #000000; font-size: 16px; font-weight: bold;" ID="dlo" ClientIDMode="Static" runat="server"></div>
<div style="width: 100%;">
<asp:Repeater runat="server" ID="rptContent">
<HeaderTemplate>
<table border="0" ID="tblInfo" style="background: #43A79A; width: 100%;" ClientIDMode="Static">
<tr>
<td>Physician Name</td>
<td>Image</td>
<td>Gender</td>
<td>Office1</td>
<td>Office2</td>
<td>Office3</td>
<td>Office4</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("Physician Name").ToString() %></td>
<td><img src="http://wp.com/<%# Eval("Image").ToString() %>" /></td>
<td><%# Eval("Gender").ToString() %></td>
<td><%# Eval("Office1").ToString() %></td>
<td><%# Eval("Office2").ToString() %></td>
<td><%# Eval("Office3").ToString() %></td>
<td><%# Eval("Office4").ToString() %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnGoAll" />
</Triggers>
</asp:UpdatePanel>