Tôi có một số dropdownlist1
có 6 mục bộ sưu tập bao gồm Select One
. Những gì tôi muốn là ddl này được thiết lập để Selectedvalue
= null. Nhưng những gì tôi nhận được là ddl của tôi luôn luôn chọn Select One
làm giá trị ban đầu của nó. Thuộc tính ddl của tôi cho Select One
được chọn: sai. Làm cách nào để đặt giá trị ddl này thành giá trị được chọn ban đầu = null?C# cách đặt giá trị mặc định dropDownList cho 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;
}
Tôi đã làm như bạn nói nhưng khi tôi chèn một cái gì đó trong txtProductName, nó không được hiển thị trong trình duyệt. –
Tuy nhiên nó là lạ, vấn đề của tôi liên quan đến câu hỏi này đang được giải quyết bằng cách chỉ thay thế txtProductName.Text = ""; với SqlProductmaster.InsertParameters ["ProductName"]. DefaultValue = txtProductName.Text; Làm việc như sự quyến rũ. –