我是新来的ASP和我遇到,我一直在一整天的问题! IM使用我的回发不断返回false,因此我的SelectedIndexChanged方法从来没有得到机会运行!
这里是我的代码:
<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>
后面我的代码(这是在同一个aspx文件的下拉列表,不知道如果多数民众赞成正常的)
<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();
}
}
任何帮助,将不胜感激! 即时通讯相当卡住,无法得到更进一步没有帮助! 谢谢!!