【问题标题】:C# Can i change (Visually) a dropdownlist AutoPostBack="true" from .cs?C# 我可以从 .cs 更改(视觉上)下拉列表 AutoPostBack="true" 吗?
【发布时间】:2015-04-01 20:59:57
【问题描述】:

我想使用代码更改 DropDown 选择(在 PageLoad 处可视化)

------------------[aspx]--------------- ---------------------

<asp:DropDownList ID="cbo" runat="server" AutoPostBack="True">
<asp:ListItem Value="3">ALL</asp:ListItem>
<asp:ListItem Value="1">YES</asp:ListItem>
<asp:ListItem Value="2">NO</asp:ListItem>
</asp:DropDownList>

------------------[/aspx]-------------- ----------------------

在我的 .cs 文件中我想这样做

------------------[cs]--------------- ---------------------

(pageload)
cbo.SelectedIndex = 1;

------------------[/cs]-------------- ----------------------

没有用

【问题讨论】:

  • 当你说它不起作用时,它是什么意思。您希望选择哪个元素?
  • 如果我能理解你... 如果你想在 posticion 1 建立 ListItem,只需在 ListItem 中添加属性“Selected”。示例:&lt;asp:ListItem Value="1" Selected="true"&gt;YES&lt;/asp:ListItem&gt;.

标签: c# drop-down-menu autopostback


【解决方案1】:

看起来您正在设置另一个下拉列表的选定索引。我认为应该是 cbo.SelectedIndex = 1

【讨论】:

  • 抱歉,我更改了下拉名称以创建此帖子...我已编辑...谢谢,但问题出在其他地方
  • no...创建帖子时这里出现了id错误
  • 您是否在同一页面的代码中的其他位置设置了 SelectedIndex?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-03
  • 1970-01-01
  • 2010-09-26
  • 2012-09-07
  • 1970-01-01
  • 2010-11-06
相关资源
最近更新 更多