gpt4 book ai didi

c# - 下拉列表 SelectedItems 回发不存在

转载 作者:太空宇宙 更新时间:2023-11-03 16:14:02 25 4
gpt4 key购买 nike

我不确定在这里做什么,我可能必须使用 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;

关于c# - 下拉列表 SelectedItems 回发不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16386612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com