我的主要目的是根据 ddlMedicalName 选择填充 ddlCity DropDownList。但我的主要问题是,尽管我尝试了几乎所有解决该问题的方法,但我无法让它触发 ddlMedicalName_OnSelectedIndexChanged 。
我知道,关于这个问题有很多问题和答案,我已经尝试了每一个,但仍然没有用。我已经读过 EnableStateView=True 不仅应该应用于 DropDownList 还应该应用于整个页面,所以我在 Web.Config 中添加了以下代码:
<system.web>
<pages styleSheetTheme="MainTheme" enableViewState="true"/>
这是我背后的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
namespace MedicalBootStrap
{
public partial class WebForm1 : System.Web.UI.Page
{
Entity.medicaldbEntities context = new Entity.medicaldbEntities();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ddlBind();
}
}
protected void ddlBind()
{
var orders = from order in context.Medicals
select new { order.MedicalID, order.medicalName, order.CityFK };
var lstsrc = orders.ToList();
ddlMedicalName.DataSource = lstsrc;
ddlMedicalName.DataTextField = "medicalname";
ddlMedicalName.DataValueField = "cityfk";
ddlMedicalName.DataBind();
}
protected void ddlMedicalName_OnSelectedIndexChanged(object sender, EventArgs e)
{
int slc = Convert.ToInt32(ddlMedicalName.SelectedItem.Value);
var orders = from order in context.Cities
where order.CityID == slc
select new { order.CityID, order.CityName};
var lstsrc = orders.ToList();
ddlMedicalName.DataSource = lstsrc;
ddlMedicalName.DataTextField = "medicalname";
ddlMedicalName.DataValueField = "cityfk";
ddlMedicalName.DataBind();
}
protected void ddlRegion_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void SearchButton_Click(object sender, EventArgs e)
{
}
}
}
这是aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="MedizinischeLeistungen.aspx.cs" Inherits="MedicalBootStrap.WebForm1" EnableViewState="true" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server" EnableViewState="true">
<table id="SearchTable">
<tr>
<td>Medizinische Leistung</td>
<td>Region</td>
<td>Stadt</td>
</tr>
<tr id="SearchDropDown">
<td>
<asp:DropDownList ID="ddlMedicalName" runat="server" EnableViewState="true"
AutoPostBack="True" AppendDataBoundItems="true"
OnSelectedIndexChanged="ddlMedicalName_OnSelectedIndexChanged">
<asp:ListItem Value="" Selected="True"> - Product - </asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlRegion" runat="server" AutoPostBack="true" EnableViewState="true"
onselectedindexchanged="ddlRegion_SelectedIndexChanged">
<asp:ListItem Value="" Selected="True"> - Product - </asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlCity" runat="server" AutoPostBack="true" EnableViewState="true"
onselectedindexchanged="ddlCity_SelectedIndexChanged">
<asp:ListItem Value="" Selected="True"> - Product - </asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:Button ID="SearchButton" runat="server" Text="Suche" onclick="SearchButton_Click" />
</td>
</tr>
</table>
</asp:Content>
任何帮助,将不胜感激