我有一個dropdownlist1
有6收集項目,包括Select One
。我想要的是這個ddl設置爲Selectedvalue
= null。但是我得到的是我的ddl總是選擇Select One
作爲它的初始值。我選擇了Select One
的ddl屬性:false。如何將此ddl設置爲初始選定值= null?C#如何設置dropDownList默認值爲selectedValue = 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;
}
我照你所說的做了,但是當我在txtProductName中插入某些東西時,它並沒有顯示在瀏覽器中。 –
然而奇怪的是,我對這個問題的問題只能通過替換txtProductName.Text =「」;來解決。與SqlProductmaster.InsertParameters [「ProductName」]。DefaultValue = txtProductName.Text; 雖然工作像魅力。 –