protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}
protected void Bind()
{
PeopleManager pm = new PeopleManager();
this.DropDownList1.DataSource = pm.SelTt();
this.DropDownList1.DataTextField = "BranchName";
this.DropDownList1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl = this.Page.FindControl("DropDownList1") as DropDownList;
Lable1.Text = ddl.SelectedValue;
}
能绑定,有值,但是当选中那个下拉框的其中一个时 却取不到,请指教
{
if (!IsPostBack)
{
Bind();
}
}
protected void Bind()
{
PeopleManager pm = new PeopleManager();
this.DropDownList1.DataSource = pm.SelTt();
this.DropDownList1.DataTextField = "BranchName";
this.DropDownList1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl = this.Page.FindControl("DropDownList1") as DropDownList;
Lable1.Text = ddl.SelectedValue;
}
能绑定,有值,但是当选中那个下拉框的其中一个时 却取不到,请指教
{
// DropDownList ddl = this.Page.FindControl("DropDownList1") as DropDownList;
Lable1.Text = DropDownList1.SelectedValue;
}
很久没做Web,有点生疏了
autopostback=true
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{DropDownList1.SelectedValue
}
嗯 autopostbback=true确实可以娶到值了
但是我发现这个是点击一下就回传刷新一次,界面很不友好,比如我一个登录信息框 前面输入下来,到下拉框选的时候就刷新了 有什么办法能不回传吗?
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlLB" runat="server" Width="15%" AutoPostBack="True" OnSelectedIndexChanged="ddlLB_SelectedIndexChanged">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
同意
楼主记得加上updatepanle 实现无刷新
<ContentTemplate>
<asp:DropDownList ID="ddlCity" runat="server" AutoPostBack="True"/>
</ContentTemplate>
</asp:UpdatePanel>string a=ddlCity.SelectedValue;