c# DropDownList用了if (!IsPostBack)就没值了
protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){selectserver.Items.Ad...
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
selectserver.Items.Add(new ListItem("0", "0"));
selectserver.Items.Add(new ListItem("1", "1"));
}
}
//按键响应获取选定的DropDownList的值
protected void Search_Click1(object sender, EventArgs e)
{
String str= selectqudao.SelectedValue;
}
然后我发现加了if (!IsPostBack) DropDownList被清空了,不加永远都只选到默认的第一条“0” 展开
{
if (!IsPostBack)
{
selectserver.Items.Add(new ListItem("0", "0"));
selectserver.Items.Add(new ListItem("1", "1"));
}
}
//按键响应获取选定的DropDownList的值
protected void Search_Click1(object sender, EventArgs e)
{
String str= selectqudao.SelectedValue;
}
然后我发现加了if (!IsPostBack) DropDownList被清空了,不加永远都只选到默认的第一条“0” 展开
1个回答
展开全部
<asp:DropDownList ID="DDL" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DDL_SelectedIndexChanged">
</asp:DropDownList>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DDL.Items.Insert(0,new ListItem("0", "0"));
DDL.Items.Insert(0, new ListItem("1", "1"));
}
}
protected void DDL_SelectedIndexChanged(object sender, EventArgs e)
{
string s = DDL.SelectedValue;
}
</asp:DropDownList>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DDL.Items.Insert(0,new ListItem("0", "0"));
DDL.Items.Insert(0, new ListItem("1", "1"));
}
}
protected void DDL_SelectedIndexChanged(object sender, EventArgs e)
{
string s = DDL.SelectedValue;
}
追问
我把我的文件发给你邮了,我的不能实现
追答
已经从新发给你啦,主要改了isPostBack 的位置
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询