[英]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.