我有三个dropdownlists
与autopostaback=true
,但问题是,对于第二个dropdownlist
,只有pageload
被调用,但它selectedindexchanged
没有被触发!我该怎么办?(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();
}
答案 0 :(得分:1)
您必须在updatepanel中放置异步触发器。试试这个:
<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>
答案 1 :(得分:0)
我最近遇到了同样的问题。我还从数据库表中填充了dropdownlist
,并且尝试了所有操作,包括在控件上设置了AutoPostBack = true
。事实证明,这是一个已知的错误,可以通过将索引0设为“选择一个人”之类的虚拟项目来解决。在此处查看帖子:
这解决了我的问题。