I'm new to ASP and I've come across a problem that I've been at all day! im using a and my postback is constantly returning false, thus my selectedIndexChanged method never gets a chance to run!
Here is my code:
<table border="1">
<tr>
<th>
Build version:
</th>
<th>
<%-- Html.DropDownList("Builds", null, new {@onchange = "onChange(this.value);" }) --%>
<%-- Html.DropDownList("BuildID", (SelectList) ViewBag.Builds, "--Select One--") --%>
<%-- Html.DropDownList("BuildDD", (IEnumerable<SelectListItem>)ViewBag.Builds, "--Select One--") --%>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="false"
DataSourceID="SqlDataSource1" DataTextField="Version"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
onprerender="DropDownList1_PreRender" onload="DropDownList1_Load">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DAContext %>"
SelectCommand="SELECT [Version] FROM [Builds]" >
</asp:SqlDataSource>
</th>
<th>
<asp:Label ID="Label1" runat="server" Text= "--Build Version--"></asp:Label>
</th>
</tr>
</table>
and my code behind (it's in the same aspx file as the dropdownlist, not sure if thats alright)
<script runat="server">
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write((sender as DropDownList).SelectedItem.Text);
Label1.Text = DropDownList1.SelectedItem.Text;
}
protected void DropDownList1_PreRender(object sender, EventArgs e)
{
base.OnPreInit(e);
DropDownList1.SelectedIndexChanged += new EventHandler(DropDownList1_SelectedIndexChanged);
}
protected void DropDownList1_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
Response.Write("Post Back is False");
DropDownList1.Items.Clear();
DropDownList1.DataSourceID = "SqlDataSource1";
DropDownList1.DataTextField = "Version";
DropDownList1.DataBind();
}
}
Any help would be appreciated! im pretty stuck and can't get much further without help! thanks!!