我的问题可能微不足道,但我无法提醒自己如何做到这一点。我有 2 个下拉列表:
<span>
<asp:DropDownList ID="DDLEditWydzial" runat="server" DataSourceID="SqlListaWydzialow"
AutoPostBack="true" DataTextField="NazwaWydzialu" DataValueField="ident"
OnSelectedIndexChanged="OnWydzialChanged" EnableViewState="true">
</asp:DropDownList>
</span>
<span>
<span style="font-size: 8pt; font-family: Arial CE">
<asp:DropDownList ID="DDLEditSale" runat="server" EnableViewState="true"
AutoPostBack="true">
</asp:DropDownList>
</span>
</span>
第一个用 via 填充SqlDataSource
,第二个根据前面的选择填充。这是由事件处理程序完成的:
protected void OnWydzialChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sworConnectionString"].ConnectionString);
conn.Open();
using (conn)
{
SqlCommand command = new SqlCommand("SELECT '-- wybierz salę --' as numer, -1 as ident UNION " +
"SELECT 'Sala ' + s.numer as numer, s.ident FROM sala s, sala_wydzial sw where s.czyus=0 and sw.id_wydzial="
+ DDLEditWydzial.SelectedValue + " and sw.id_sala = s.ident", conn);
SqlDataReader salaReader = command.ExecuteReader();
DDLEditSale.AppendDataBoundItems = true;
DDLEditSale.DataSource = salaReader;
DDLEditSale.DataTextField = "numer";
DDLEditSale.DataValueField = "ident";
DDLEditSale.DataBind();
conn.Close();
conn.Dispose();
}
}
然后,当我从第二个列表中选择值时,回发并在刷新列表后包含数据,但没有选择第二个 DDL 中的任何内容。我检查了 Page_Load 并且 DDLEditSale 是空的。
有任何想法吗?:)
编辑: OnInit 和 InitializeComponent 代码(它由 ZedGraph 生成):
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.ZedGraphWeb1.RenderGraph += new ZedGraph.Web.ZedGraphWebControlEventHandler(this.OnRenderGraph);
}