Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script src="/jquery-1.10.2.min.js"></script>
- <script type='text/javascript'>
- $(document).ready(function(){
- if($('#drStatus').find("option:selected").val() == "Choose..") {
- $('#drStatus').val("In Progress");
- }
- });
- </script>
- $(document).ready(function(){
- if($("select[title='Status']").find("option:selected").val() == "Choose..")
- {
- $("select[title='Status']").val("InProgress");
- }
- });
- $(document).ready(function(){
- if($("select[title='_title of column_'] option:selected").val() == "Choose.."){
- $("select[title='_title of column_']").val("In progress...");
- }
- });
- protected void Page_Load(object sender, EventArgs e)
- {
- string selectedValue = status.SelectedValue.ToString();
- if(selectedValue == "Choose")
- {
- //This is very simple but will result in an error if the dropdown already has a
- status.SelectedValue == "In Progress"
- or
- //add any of below code which should not result in an error in case there already is a selected item.
- //add error checking, just an example, FindByValue may return null
- status.Items.FindByValue("Yourvalue").Selected = true;
- or
- //add error checking, just an example, FindByText may return null
- status.Items.FindByText("In Progress").Selected = true;
- }
- }
- <asp:DropDownList ID="drStatus" runat="server" CssClass="UniqueClassName">
- <asp:ListItem Text="Choose" Value="-1"></asp:ListItem>
- <asp:ListItem Text="In Progess" Value="1"></asp:ListItem>
- <asp:ListItem Text="Closed" Value="2"></asp:ListItem>
- </asp:DropDownList>
- //set which text you want find
- var textToFind = 'In Progress';
- $(".UniqueClassName > option").each(function() {
- if (this.text === textToFind) {
- $(this).prop('selected', 'selected');
- }
- });
- $('select[title="Origin State"] option:contains("GA")').prop({ selected: true });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement