本文介绍了Asp.net的DropDownList的IsPostBack是alwasy假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新来的ASP和我遇到,我一直在一整天的问题!即时通讯使用的是和我回发不断返回false,因此我的SelectedIndexChanged方法从来没有得到机会运行!
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!
下面是我的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>
和我的背后code(这是在同一个aspx文件作为DropDownList的,不知道如果多数民众赞成好吧)
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();
}
}
任何帮助将是AP preciated! IM pretty卡住而无法得到更进一步没有帮助!谢谢!
Any help would be appreciated! im pretty stuck and can't get much further without help! thanks!!
推荐答案
在您的下拉列表中设置的AutoPostBack =真正的
set AutoPostBack="true"
in your dropdown list
这篇关于Asp.net的DropDownList的IsPostBack是alwasy假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!