[英]selectedindexchanged event not firing
i have three dropdownlists
with autopostaback=true
,but the problem is that for second dropdownlist
only pageload
is called but it's selectedindexchanged
is not firing!我有三个带有autopostaback=true
dropdownlists
,但问题是第二个dropdownlist
只调用了pageload
但它的selectedindexchanged
没有触发! what can i do?( dropdownlists
are in updatepanel
)我能做什么?( dropdownlists
在更新updatepanel
)
EDIT:
protected void Page_Load(object sender, EventArgs e)
{
if (DDL_d1.Items.Count == 0)
{
SqlDataReader dr = null;
DbAccessor db = new DbAccessor();
dr = db.SqlSelectS("true", "SELECT Fname FROM [Tbl_Amoozesh]");
DDL_d1.Items.Clear();
while (dr.Read())
DDL_d1.Items.Add(dr[0].ToString());
db.Dispose();
}
}
protected void d1(object sender, EventArgs e)
{
DDL_d1.AutoPostBack = false;
SqlDataReader dr = null;
DbAccessor db = new DbAccessor();
dr = db.SqlSelectS(DDL_d1.SelectedValue,"SELECT Fname FROM [Tbl_Amoozesh] where Fname = @a");
DDL_d2.Items.Clear();
DDL_d2.Items.Add(new ListItem("hi"));
while (dr.Read())
DDL_d2.Items.Add(dr[0].ToString());
db.Dispose();
}
protected void d2(object sender, EventArgs e)
{
SqlDataReader dr = null;
DbAccessor db = new DbAccessor();
dr = db.SqlSelectS(DDL_d2.SelectedValue, "SELECT Lname FROM [Tbl_Amoozesh] where Fname = @a");
DDL_d3.Items.Clear();
while (dr.Read())
DDL_d3.Items.Add(dr[0].ToString());
db.Dispose();
}
You have to put an asynchronous trigger in your updatepanel.您必须在更新面板中放置一个异步触发器。 Try this:试试这个:
<asp:UpdatePanel id="up1" runat="server" updatemode="conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddl" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<%-- your content here --%>
<asp:DropdownList id="ddl" AutoPostback="true" OnSelectedIndexChanged="handler" />
</ContentTemplate>
</asp:UpdatePanel>
I recently had the same problem.我最近遇到了同样的问题。 I was also populating my dropdownlist
from a database table and I tried everything including setting AutoPostBack = true
on the control.我还从数据库表中填充我的dropdownlist
列表,我尝试了一切,包括在控件上设置AutoPostBack = true
。 It turns out this is a known bug that you can resolve by making index 0 a dummy item like 'Select a person'.事实证明,这是一个已知的错误,您可以通过将索引 0 设为像“选择一个人”这样的虚拟项目来解决该错误。 Check out the post here:查看这里的帖子:
https://forums.asp.net/t/1275349.aspx?Dropdownlist+not+firing+SelectedIndexChanged+on+first+item+with+autopostback+true https://forums.asp.net/t/1275349.aspx?Dropdownlist+not+firing+SelectedIndexChanged+on+first+item+with+autopostback+true
This solved my problem.这解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.