【问题标题】:Auto Select one item on Dropdownlist asp.net c#自动选择下拉列表中的一项 asp.net c#
【发布时间】:2019-10-01 06:16:03
【问题描述】:

我有下拉列表,其中列表项为是和否。我希望页面上显示“否”,但 ListItem 上的 Selected="true" 不起作用。

<asp:DropDownList ID="ddlIsDistributor" runat="server">
                    <asp:ListItem  Value="1" Text="Yes">Yes</asp:ListItem>
                    <asp:ListItem  Value="0" Text="No" Selected="True">No</asp:ListItem>

                </asp:DropDownList>

【问题讨论】:

  • 我相信你应该尝试使用true small caps ...否则你也可以在后面添加一个代码,如ddlIsDistributor.SelectedValue = 1
  • 查看declarative syntaxasp:DropDownListSelected="True" 应该适用于asp:ListItem。我什至无法重现您的问题。
  • 我现在解决了这个问题。谢谢。

标签: c# asp.net dropdown


【解决方案1】:

在页面加载事件中调用这段代码,以便在加载时从下拉列表中选择所需的值:ddlIsDistributor.SelectedIndex = 0;

【讨论】:

  • 您的问题应该有答案,接受一个,提供解决方案或删除它:)
猜你喜欢
  • 1970-01-01
  • 2020-01-31
  • 1970-01-01
  • 1970-01-01
  • 2012-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多