Note that there are some explanatory texts on larger screens.

plurals
  1. PODropdown selected value isn't getting selected, it always shows the first value in selection
    primarykey
    data
    text
    <p>I have two dropdowlists ddprojecttype and ddprojectname. On selecting project type I'm populating projectnames into ddprojectname with jQuery and AJAX. It's showing properly only.</p> <p>However, whenever I am trying to make a selection on the dropdownlist it always selects the first item. And also it's behaviour is peculiar: while I am viewing the aspx page in the browser then it's showing all the project names into the dropdown. Whereas in case of viewing the source it's not showing the dropdown options at all.</p> <p>I will post the page code as well as the html for that and the jQery scripts for them:</p> <pre><code> &lt;asp:DropDownList ID="ddProjectTypeID" runat="server" &gt; &lt;/asp:DropDownList&gt; &lt;asp:DropDownList ID="ddProjectName" runat="server" &gt; &lt;/asp:DropDownList&gt; </code></pre> <p>The jQuery for the scripts which loads the project names successfully is:</p> <pre><code>$('[id*="ddProjectTypeID"]').change(function() { if ($(this).find(":selected").text() != "--Select--") { $.ajax({ type: 'POST', contentType: "application/json; charset=utf-8", url: 'Services/Service.asmx/GetProjectNames', data: '{"p_type_id":"' + $(this).find(":selected").val() + '"}', dataType: "json", success: function(data, textStatus) { if (textStatus == "success") { var myObject = data.d; $('[id*="ddProjectName"] &gt;option').remove(); $('[id*="ddProjectName"]').append($('&lt;option&gt;&lt;/option&gt;').val("--Select--").html("--Select--")); for (var i = 0; i &lt;= myObject.length - 1; i++) { $('[id*="ddProjectName"]').append($('&lt;option&gt;&lt;/option&gt;').val(myObject[i].project_id) .html(myObject[i].project_name)); } } }, error: function(data, textStatus) { alert('An error has occured retrieving data!'); } }); } }); </code></pre> <p>It loads the names successfully onto the ddprojectnames dropdownlist:</p> <p>Curiously whenever I am executing this code : </p> <pre><code>protected void btnSubmit_Click(object sender, EventArgs e) { ScheduleDetails scdetails = new ScheduleDetails(); scdetails.ProjectTypeID = ddProjectTypeID.SelectedItem.Value; scdetails.ProjectID = ddProjectName.SelectedItem.Value; } </code></pre> <p>it only gets scdetails.ProjectTypeID = 1 but scdetails.ProjectID = "--Select--" </p> <p>I am not getting the reason why. Although I have loaded the projectnames from the cascading dropdown from projecttypeID even then also it gets "--select--" as result whenever irrespective I chose any value from ddprojectname ...</p> <p>Why is this happening? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload