[英]Dropdown List SelectedItems Postback Not there
我不确定在这里做什么,我可能必须使用viewstates,但是我需要帮助。
我有一个下拉列表,我没有数据绑定。 我想知道我是否应该执行Page.IsPostBack
而不是databind。
<asp:DropDownList ID="ddlWeeklyWeightIn" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:DropDownList>
现在在我后面的代码中有这个:
protected void Button1_Click(object sender, EventArgs e)
{
string wwin = "";
wwin = ddlWeeklyWeightIn.SelectedItem.Text;
}
在按钮上单击总是“ 1”,而不是所选项目。
谢谢
尝试将EnableViewState =“ True”添加到下拉控件中。
回发导致重置您选择的值。 请使用if(!IsPostBack)
或使用更新面板来防止回发。
这只是为了确保但您可以尝试使用:
<asp:DropDownList ID="ddlWeeklyWeightIn" runat="server">
<asp:ListItem Text="1"></asp:ListItem>
<asp:ListItem Text="2"></asp:ListItem>
<asp:ListItem Text="3"></asp:ListItem>
<asp:ListItem Text="4"></asp:ListItem>
</asp:DropDownList>
您能否检查您是否不只是在页面初始化期间设置所选项目?
Aspx方面:将autopostback = true添加到下拉属性,并使用listitem,如下所示:ListItem Text =“ 4” Value =“ 4”>等
后面的代码: string wwin =“”; wwin = ddlWeeklyWeightIn.SelectedValue;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.