0

私の問題はおそらく些細なことですが、その方法を思い出すことができません。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>

1 つSqlDataSource目は via で埋められ、2 つ目は前の選択に応じて埋められます。これは、イベント ハンドラーによって行われます。

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();
    }
}

次に、2番目のリストから値を選択すると、ポストバックが来て、リフレッシュリストの後にデータが含まれていますが、2番目の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);
}
4

1 に答える 1

0

私はに変更SqlDataSourcesしましたがObjectDataSources、うまくいくようです.SessionでIDを保持する必要があるだけですwydzial. 少し時間があるときにコードを貼り付けます:)

于 2013-10-04T13:11:24.043 に答える