code_junkie

How to set Custom Text into DropdownList in ASP.Net

Nov 13th, 2011
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. <asp:DropDownList AppendDataBoundItems="true" ID="yourListId" runat="server">
  2. <asp:ListItem Text="Select something" Value="-1" />
  3. </asp:DropDownList>
  4.  
  5. function addFirstItem(list, text, value)
  6. {
  7. var newOption = document.createElement("option");
  8. newOption.text = text;
  9. newOption.value = value;
  10. list.options.add(newOption);
  11. }
  12.  
  13. addFirstItem(document.getElementById("yourListId"), "Select something", "-1");
  14.  
  15. $("#yourListId option:first").before("<option value='-1'>Select something</option>");
  16.  
  17. <asp:DropDownList AppendDataBoundItems="true" ID="yourListId" runat="server">
  18. <items>
  19. <asp:ListItem Text="Select something" Value="-1">--Select Something--</asp:ListItem>
  20. </items>
  21. </asp:DropDownList>
Add Comment
Please, Sign In to add comment