NurveTech
asked on
DropDownList Default Selection not working
Problem in a nut shell: This is done with ASP.NET/C#/MVC2
When the page loads it has the proper data in the drop down list, but it is not showing the proper item as being selected. It defaults to the first item in the list, even though the page source says it should be selecting the 2nd option down.
HELP!!
I need the page to sort the drop down to the Selected="Selected" Item.
Here is the code that renders this section of the page.
<tr>
<td>
Complaint Detail:
</td>
<td>
<select id="ComplaintDetail" name="ComplaintTypeID" style="width: 340px">
<%
foreach (var item in CustomerComplaintSystem_MV C2.Informa tionTypeLi st.SelectI nformation TypeListBy BbbTypeID( Model.Comp laintTypeC ategoryID) )
{
if (item.InformationTypeListI D.Value.To String() == Model.ComplaintTypeID.Valu e.ToString ())
{
%>
<option value="<%=item.Information TypeListID %>" selected="selected"><%=ite m.Name%></ option>
<% }
else
{ %>
<option value="<%= item.InformationTypeListID %>"><%=ite m.Name%></ option>
<% } %>
<% } %>
</select>
</td>
</tr>
Here is the html after it is rendered.
<tr>
<td>
Complaint Detail:
</td>
<td>
<select id="ComplaintDetail" name="ComplaintTypeID" style="width: 340px">
<option value="6e2de3e7-7cc9-4d51- be46-bc439 c137a64">I nadequate Email Response</option>
<option value="5b6dfcf0-537d-401d- a17d-5016c 6dd9e98" selected="selected">Compla int - Paralegal Knowledge</option>
<option value="7e16ec5c-4612-466c- a10e-740d1 a9f03b2">C omplaint - Paralegal Demeanor</option>
<option value="40bfc518-e6a2-4f13- 8eeb-64988 d5f085f">D ata Entry Errors</option>
<option value="88d05997-ce18-4b1b- acfd-606e5 d6e93ba">S ervices Not Performed Adequately</option>
<option value="ccd0386f-fe72-4e9f- bf8f-3ec07 98fc2c2">O ther Customer Service</option>
</select>
</td>
</tr>
Notice how the second option should be the selected option when you look at the page, now check my screen shot and you will see that it just defaults to the top item in the list and doesnt sort down,
This call gets made on page load to populate the drop down after ddlComplaintType has been poopulated
function GetComplaintTypes() {
$.getJSON('/Tickets/GetCom plaintType sEdit/?Com plaintType ID=' + $("#ddlComplaintType").val (), function(data) { $("#ComplaintDetail").fill Select(dat a); });
}
This method sits in my controller and is what i use to populate the dropdown list.
public JsonResult GetComplaintTypes(Guid ComplaintTypeID)
{
List<CustomerComplaintSyst em_MVC2.Mo dels.DropD ownListDat a> data = new List<CustomerComplaintSyst em_MVC2.Mo dels.DropD ownListDat a>();
InformationTypeList[] options = InformationTypeList.Select Informatio nTypeListB yBbbTypeID (Complaint TypeID);
DropDownListData dataOption1 = new DropDownListData();
dataOption1.TextField = "--Select One--";
dataOption1.ValueField = "0";
data.Add(dataOption1);
foreach (var item in options)
{
DropDownListData dataOption = new DropDownListData();
dataOption.TextField = item.Name;
dataOption.ValueField = item.InformationTypeListID .ToString( );
data.Add(dataOption);
}
return Json(data, JsonRequestBehavior.AllowG et);
}
When the page loads it has the proper data in the drop down list, but it is not showing the proper item as being selected. It defaults to the first item in the list, even though the page source says it should be selecting the 2nd option down.
HELP!!
I need the page to sort the drop down to the Selected="Selected" Item.
Here is the code that renders this section of the page.
<tr>
<td>
Complaint Detail:
</td>
<td>
<select id="ComplaintDetail" name="ComplaintTypeID" style="width: 340px">
<%
foreach (var item in CustomerComplaintSystem_MV
{
if (item.InformationTypeListI
{
%>
<option value="<%=item.Information
<% }
else
{ %>
<option value="<%= item.InformationTypeListID
<% } %>
<% } %>
</select>
</td>
</tr>
Here is the html after it is rendered.
<tr>
<td>
Complaint Detail:
</td>
<td>
<select id="ComplaintDetail" name="ComplaintTypeID" style="width: 340px">
<option value="6e2de3e7-7cc9-4d51-
<option value="5b6dfcf0-537d-401d-
<option value="7e16ec5c-4612-466c-
<option value="40bfc518-e6a2-4f13-
<option value="88d05997-ce18-4b1b-
<option value="ccd0386f-fe72-4e9f-
</select>
</td>
</tr>
Notice how the second option should be the selected option when you look at the page, now check my screen shot and you will see that it just defaults to the top item in the list and doesnt sort down,
This call gets made on page load to populate the drop down after ddlComplaintType has been poopulated
function GetComplaintTypes() {
$.getJSON('/Tickets/GetCom
}
This method sits in my controller and is what i use to populate the dropdown list.
public JsonResult GetComplaintTypes(Guid ComplaintTypeID)
{
List<CustomerComplaintSyst
InformationTypeList[] options = InformationTypeList.Select
DropDownListData dataOption1 = new DropDownListData();
dataOption1.TextField = "--Select One--";
dataOption1.ValueField = "0";
data.Add(dataOption1);
foreach (var item in options)
{
DropDownListData dataOption = new DropDownListData();
dataOption.TextField = item.Name;
dataOption.ValueField = item.InformationTypeListID
data.Add(dataOption);
}
return Json(data, JsonRequestBehavior.AllowG
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I thought I would have a stab at it without double checking. Couldn't remember off the top of my head and just assumed it was the same format as checkboxes.
DaTribe
DaTribe
ASKER
I solved my own problem.
<option value="<%=item.Information
DaTribe