小编Com*_*irl的帖子

C#如何为selectedValue = null设置dropDownList的默认值

我有一个dropdownlist1有6个收集项目,包括Select One.我想要的是这个ddl被设置为Selectedvalue= null.但我得到的是我的ddl始终选择Select One作为其初始值.我Select One选择了我的ddl属性:false.如何将此ddl设置为初始选定值= null?

<asp:DropDownList ID="DropDownList1" runat="server" Visible="False" Width="146px">
     <asp:ListItem>Ceiling Speaker</asp:ListItem>
     <asp:ListItem>Remote Microphone</asp:ListItem>
     <asp:ListItem>Digital Source Player</asp:ListItem>
     <asp:ListItem>Remote paging Console</asp:ListItem>
     <asp:ListItem>Modular Mixer</asp:ListItem>
     <asp:ListItem>Select One</asp:ListItem>
</asp:DropDownList>


if (String.IsNullOrEmpty(txtSearchProductname.Text))
{
   if (DropDownList1.SelectedValue == null)
   {
       txtProductName.Text = "";
   }
   else
   {
       SqlProductmaster.InsertParameters["ProductName"].DefaultValue = DropDownList1.SelectedValue.ToString();
   }
}
else
{
    SqlProductmaster.InsertParameters["ProductName"].DefaultValue = txtProductName.Text;
}
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net drop-down-menu

8
推荐指数
1
解决办法
7万
查看次数

c#if else语句

我有一个问题,因为我的编码不起作用(错误),我不知道如何纠正它.你们可以检查一下这句话是对还是错?我的条件是1)如果textbox productname为null或为空且未选择dropdownlist1,则text将为null.2)如果文本框产品名称已填充(字符串),则文本将填入3)如果textbox productname为null或为空且选择了dropdownlist1,则文本将选择值.请参考粗体文字.高兴!!

if (String.IsNullOrEmpty(txtSearchProductname.Text) == true)
    {
        if (**DropDownList1.SelectedValue.ToString == null**)
        {
            txtSearchProductname.Text = " ";
        }
        else 
        {
            SqlProductmaster.InsertParameters["ProductName"].DefaultValue = DropDownList1.SelectedValue.ToString();
        }                
     }
    else 
    {
        SqlProductmaster.InsertParameters["ProductName"].DefaultValue = txtProductName.Text.ToString();
    }
Run Code Online (Sandbox Code Playgroud)

c# asp.net if-statement

1
推荐指数
1
解决办法
4355
查看次数

标签 统计

asp.net ×2

c# ×2

.net ×1

drop-down-menu ×1

if-statement ×1