このように、あなたはこれを達成するために、HTML + jQueryのを必要とするだろう見せたいです。この後
<asp:DropDownList ID="ddlyear" runat="server">
<asp:ListItem>Experience</asp:ListItem>
<asp:ListItem>Fresher</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
、あなたは削除し、プレースホルダを取り付け直すことで魔法を行うには、あなたのjQueryを必要としています。
<script>
var isChanged = false;
$(function() {
$('#ddlyear').focusin(function() {
if (!isChanged) {
// this removes the first item which is your placeholder if it is never changed
$(this).find('option:first').remove();
}
});
$('#ddlyear').change(function() {
// this marks the selection to have changed
isChanged = true;
});
$('#ddlyear').focusout(function() {
if (!isChanged) {
// if the control loses focus and there is no change in selection, return the first item
$(this).prepend('<option selected="selected" value="0">Experience</option>');
}
});
});
</script>
だけnugetパッケージとしてインストールするか、手動でダウンロードして、ASPXで宣言を追加し、あなたがこれを使用するjQueryのを必要とすることに注意してください。
<head runat="server">
<title></title>
// Sample only, you can place it in any location or use any version
<script src="../scripts/jquery-2.2.2.min.js"></script>
</head>
プレースホルダは、それが唯一の理由は、あなたが宣言した最初のオプションで示し、文句を言わない仕事を属性。 – DevEstacion
それから何が効きますか? – amit
私のために働いています....試してみてください –