我有一个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) 我有一个问题,因为我的编码不起作用(错误),我不知道如何纠正它.你们可以检查一下这句话是对还是错?我的条件是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)