我不确定在这里做什么,我可能必须使用 View 状态,但我需要帮助。
我有一个下拉列表,我没有数据绑定(bind)。我会知道我是否应该执行 Page.IsPostBack
而不是数据绑定(bind)。
<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”,而不是选中的项目。
谢谢
Aspx 端:将 autopostback=true 添加到下拉属性并使用 listitem 如下:ListItem Text="4"Value="4"> 等
代码隐藏: string wwin = ""; wwin = ddlWeeklyWeightIn.SelectedValue;
我是一名优秀的程序员,十分优秀!