My problem's probably trivial, but I can't remind myself how to do that. I have 2 dropdown lists:
<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>
First one is filled with via SqlDataSource
, second is filled depending on choice in previous. This is done by an event handler:
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();
}
}
Then, when I chose value from 2nd list, comes postback and after a refresh list contains with data, but nothing in 2nd DDL is selected. I've checked Page_Load and DDLEditSale is empty then.
Any ideas?:)
EDIT: OnInit and InitializeComponent code (it's generated by 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);
}
I've changed SqlDataSources
to ObjectDataSources
and it seems to work, just need to keep id of wydzial
in Session. I'll paste code when I have a little time:)