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! what can i do?( dropdownlists
are in 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. It turns out this is a known bug that you can resolve by making index 0 a dummy item like 'Select a person'. Check out the post here:
This solved my problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.