Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. <script src="/jquery-1.10.2.min.js"></script>
  2. <script type='text/javascript'>
  3. $(document).ready(function(){
  4. if($('#drStatus').find("option:selected").val() == "Choose..") {
  5. $('#drStatus').val("In Progress");
  6. }
  7. });
  8. </script>
  9.  
  10. $(document).ready(function(){
  11. if($("select[title='Status']").find("option:selected").val() == "Choose..")
  12. {
  13. $("select[title='Status']").val("InProgress");
  14. }
  15. });
  16.  
  17. $(document).ready(function(){
  18. if($("select[title='_title of column_'] option:selected").val() == "Choose.."){
  19. $("select[title='_title of column_']").val("In progress...");
  20. }
  21. });
  22.  
  23. protected void Page_Load(object sender, EventArgs e)
  24. {
  25. string selectedValue = status.SelectedValue.ToString();
  26. if(selectedValue == "Choose")
  27. {
  28. //This is very simple but will result in an error if the dropdown already has a
  29. status.SelectedValue == "In Progress"
  30.  
  31. or
  32. //add any of below code which should not result in an error in case there already is a selected item.
  33.  
  34. //add error checking, just an example, FindByValue may return null
  35. status.Items.FindByValue("Yourvalue").Selected = true;
  36.  
  37. or
  38. //add error checking, just an example, FindByText may return null
  39. status.Items.FindByText("In Progress").Selected = true;
  40. }
  41. }
  42.  
  43. <asp:DropDownList ID="drStatus" runat="server" CssClass="UniqueClassName">
  44. <asp:ListItem Text="Choose" Value="-1"></asp:ListItem>
  45. <asp:ListItem Text="In Progess" Value="1"></asp:ListItem>
  46. <asp:ListItem Text="Closed" Value="2"></asp:ListItem>
  47. </asp:DropDownList>
  48.  
  49. //set which text you want find
  50. var textToFind = 'In Progress';
  51.  
  52. $(".UniqueClassName > option").each(function() {
  53. if (this.text === textToFind) {
  54. $(this).prop('selected', 'selected');
  55. }
  56. });
  57.  
  58. $('select[title="Origin State"] option:contains("GA")').prop({ selected: true });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement