如何选择在另一个页面中选择的相同选项
本文关键字:选择 选项 另一个 何选择 | 更新日期: 2023-09-27 18:03:59
我有几个下拉列表在我的主页:
<asp:DropDownList style="width: 245px;" class="default" ID="slcLocation" runat="server" ClientIDMode="Static" AppendDataBoundItems="true">
</asp:DropDownList>
<br /><br />
<asp:DropDownList style="width: 245px;" class="default" ID="slcSpecialty" runat="server" ClientIDMode="Static" AppendDataBoundItems="true">
</asp:DropDownList>
<br /><br />
<asp:DropDownList style="width: 245px;" class="default" ID="slcGender" runat="server" ClientIDMode="Static" AppendDataBoundItems="true">
<asp:ListItem Text="Any Gender" Value="" Selected="True" />
<asp:ListItem Text="Male" Value="1" />
<asp:ListItem Text="Female" Value="2" />
</asp:DropDownList>
<asp:Button ID="btnGoAll" class="loginButton" style="padding: 10px; float: right;" Text="Search All" OnClick="btnGoAll_Click" runat="server" ClientIDMode="Static" />
前两个是从后面的代码自动填充的,而最后一个是在我的aspx页面中填充的。生成页面后,源代码如下所示:
<select name="ctl00$FeaturedContent$slcLocation" id="slcLocation" class="default" style="width: 245px;">
<option value="">All Locations</option>
<option value="89">Theall Road</option>
<option value="2535">Mamaroneck Avenue</option>
<option value="1947">Huguenot Street</option>
<option value="2666">Huguenot Street(1)</option>
<option value="2435">verhill Road</option>
<option value="87">estchester Avenue</option>
<option value="1121">estchester Avenue</option>
<option value="90">estchester Avenue</option>
<option value="100">avis Avenue</option>
<option value="93">te Plains Road Suite 270</option>
<option value="1532">ic Surgery at WESTMED</option>
<option value="1606">l, 73 Market Street</option>
<option value="1241">nter at WESTMED</option>
</select>
<br /><br />
<select name="ctl00$FeaturedContent$slcSpecialty" id="slcSpecialty" class="default" style="width: 245px;">
<option value="">All Specialties</option>
<option value="553">Allergy and Immunology</option>
<option value="315">Anesthesiology</option>
<option value="140">Breast Surgery</option>
<option value="141">Cardiology</option>
<option value="2672">Care Management</option>
<option value="2509">Chiropractic Medicine</option>
<option value="688">Clinical Laboratory</option>
<option value="337">Colon and Rectal Surgery</option>
<option value="145">Critical Care</option>
<option value="143">Dermatology / Cosmetic</option>
<option value="633">Diabetes Education</option>
<option value="144">Ear, Nose and Throat</option>
<option value="146">Endocrinology</option>
<option value="165">Eye Care</option>
<option value="155">Family Medicine</option>
<option value="156">Gastroenterology</option>
<option value="157">General Surgery</option>
<option value="158">Geriatric Medicine</option>
<option value="1841">Gynecologic Oncology</option>
<option value="2345">Hand Surgery</option>
<option value="159">Hematology and Oncology</option>
<option value="722">Hospitalist</option>
<option value="160">Infectious Diseases</option>
<option value="161">Internal Medicine</option>
<option value="2069">Interventional Radiology</option>
<option value="2318">Maternal Fetal Medicine</option>
<option value="2654">Medical Oncology</option>
<option value="2309">Mohs Surgery</option>
<option value="162">Nephrology</option>
<option value="163">Neurology</option>
<option value="652">Nutrition</option>
<option value="164">Obstetrics and Gynecology</option>
<option value="634">Optical Shop</option>
<option value="166">Orthopedic Surgery</option>
<option value="1951">Palliative Medicine</option>
<option value="1589">Pathology</option>
<option value="167">Pediatrics and Adolescent Medicine</option>
<option value="168">Physical Medicine and Rehabilitation</option>
<option value="169">Plastic Surgery</option>
<option value="170">Podiatry</option>
<option value="171">Pulmonology</option>
<option value="2061">QCOI</option>
<option value="1460">Radiation Oncology</option>
<option value="691">Radiology</option>
<option value="172">Rheumatology</option>
<option value="2520">Sleep Center</option>
<option value="2145">Thoracic Surgery</option>
<option value="951">Urgent Care</option>
<option value="173">Urology</option>
<option value="456">Vascular Surgery</option>
<option value="174">Weight Management</option>
</select>
<br /><br />
<select name="ctl00$FeaturedContent$slcGender" id="slcGender" class="default" style="width: 245px;">
<option selected="selected" value="">Any Gender</option>
<option value="1">Male</option>
<option value="2">Female</option>
</select>
<input type="submit" name="ctl00$FeaturedContent$btnGoAll" value="Search All" id="btnGoAll" class="loginButton" style="padding: 10px; float: right;" />
我有一个按钮点击选项在我的主页像这样保存变量在一个会话:
protected void btnGoAll_Click(object sender, EventArgs e) {
var locText = slcLocation.SelectedItem.Text;
var speText = slcLocation.SelectedItem.Text;
var genText = slcGender.SelectedItem.Text;
Session["LocationText"] = locText;
Session["SpecialtyText"] = speText;
Session["GenderText"] = genText;
Response.Redirect("~/physicians.aspx", false);
}
我在另一个页面(physician.aspx)中有相同的ASPX代码,它显示相同的下拉列表。我想要的是,当用户从主页单击提交按钮时,下拉列表将自动填充physician.aspx
页面中的这些选择。
我在physician.asp
页有这样的东西:
public partial class physicians : System.Web.UI.Page {
string cString = "";
SqlConnection Conn;
string strQueryAll = "*";
string sqlCode = "";
string theLocation = "", theSpecialty = "", theGender = "";
string locVal = "", speVal = "", genVal = "";
string lVal = "", sVal = "", gVal = "";
int rowCount = 0;
protected void Page_Load(object sender, EventArgs e) {
if (!Page.IsPostBack) {
PopulatePhysician();
ASPopulateLocation();
ASPopulateSpecialty();
}
if (Session["LocationText"] != null && Session["SpecialtyText"] != null && Session["GenderText"] != null) {
//dlo.InnerHtml = "Successfully retrieved " + (string)Session["LocationText"];
//btnGoAll_OnClick(null, null);
}
}
}
我也有一个按钮在physician.aspx
页面,我想自动点击,所以它就像如果用户点击医师页面。
我只是需要一些帮助来弄清楚如何实现会话传输和自动填充。我应该在会话中获取文本或值,以及如何将其应用于physician.aspx
页面?
我想我需要一个函数,在页面加载后执行,因为控件尚未初始化?
可以用Javascript实现这个功能吗?我如何使它与我通过c#接收的会话一起工作?
你可以有一个像
public void OnBtnClick()
{
// add the code with the query to database
}
在页面加载时你可以像这样调用这个函数
protected void Page_Load(object sender, EventArgs e) {
if (!Page.IsPostBack) {
PopulatePhysician();
ASPopulateLocation();
ASPopulateSpecialty();
}
if (Session["LocationText"] != null && Session["SpecialtyText"] != null && Session["GenderText"] != null) {
this.OnBtnClick();
}
}
和按钮点击事件处理程序只是再次调用公共函数
protected void btnGoAll_Click(object sender, EventArgs e) {
this.OnBtnClick();
}