C# C“我可以(直观地)更改dropdownlist AutoPostBack=”吗;“真的”;来自.cs?

C# C“我可以(直观地)更改dropdownlist AutoPostBack=”吗;“真的”;来自.cs?,c#,drop-down-menu,autopostback,C#,Drop Down Menu,Autopostback,我想使用代码更改下拉选择(在页面加载时可视) -----------------------------[aspx]------------------------------------ <asp:DropDownList ID="cbo" runat="server" AutoPostBack="True"> <asp:ListItem Value="3">ALL</asp:ListItem> <asp:ListItem Value="1">Y

我想使用代码更改下拉选择(在页面加载时可视)

-----------------------------[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>
(pageload)
cbo.SelectedIndex = 1;
-----------------------------[cs]------------------------------------

<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>
(pageload)
cbo.SelectedIndex = 1;

它不工作

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

对不起,我更改了下拉列表名称来创建此帖子…我编辑了…谢谢,但问题是其他一些问题没有…id错误是在创建帖子的过程中犯的。您是否在同一页面的代码中的其他地方设置SelectedIndex?当您说它不工作时,这是什么意思。您希望选择哪个元素?如果我能理解您的意思。。。如果您想在posticion
1
建立
ListItem
,只需在
ListItem
中添加属性“Selected”。示例: