How Do I Select two items on a DropDownList row? RRS feed

  • Question

  • User-1244692504 posted

    Hi, Kindly assist with the code below. I intend to select two items on a DropDownList row. (DebitNoteNo and ClientCode). My codes are stated below:

            #region Debit Notes Drop Down List
            public static IEnumerable<ClientDebitNoteDTO> DebitNoteDropDownList(this HtmlHelper htmlHelper)
                 var dnoteCodeList = cacheService.Get(Constants.General.DebitNoteList) as IList<ClientDebitNoteDTO>;
                if (dnoteCodeList == null)
                    var underwritingService = ((IIocContainer)context.Application["container"]).Resolve<IUnderwritingService>();
                    dnoteCodeList = underwritingService.DebitNoteDropDownList(1, 5000, Constants.SortField.DebitNoteNo, Constants.SortOrder.Ascending, string.Empty, null).Select(f =>
                            new ClientDebitNoteDTO
                                DebitNoteNo = f.DebitNoteNo,
                                ClientCode = f.ClientCode,
                                ClientName = string.Format("{0} | {1} | {2}",
                                   f.DebitNoteNo, f.ClientCode, f.ClientName)
                    dnoteCodeList.Insert(0, new ClientDebitNoteDTO() { DebitNoteNo = string.Empty, ClientName = "Please select the debit note...." });
                    //cacheService.Add(Constants.General.DebitNoteList, dnoteCodeList);
                return dnoteCodeList;

    The DTO Model is 

     public class ClientDebitNoteDTO
            public string DebitNoteNo { get; set; }
            public string ClientCode { get; set; }
            public string ClientName { get; set; }

    The View is

                    <div class="form-group">
                        @Html.LabelFor(model => model.Account_ClientReceipt.DebitNoteNo, htmlAttributes: new { @class = "control-label col-md-2" })
                        <div class="col-md-10">
                            <div data-tip="Please select Client Debit Note">
                                @Html.DropDownList("Account_ClientReceipt.DebitNoteNo", new SelectList(Html.DebitNoteDropDownList(), "DebitNoteNo", "ClientName", Model.Account_ClientReceipt.DebitNoteNo), new { id = "Account_ClientReceipt.DebitNoteNo", @class = "form-control input-sm" })
                                @Html.ValidationMessageFor(model => model.Account_ClientReceipt.DebitNoteNo, "", new { @class = "text-danger" })
                    <br />
                    <div class="form-group">
                        @Html.LabelFor(model => model.Account_ClientReceipt.ClientCode, htmlAttributes: new { @class = "control-label col-md-2" })
                        <div class="col-md-10">
                            <div data-tip="Please select Client">
                                @Html.DropDownList("Account_ClientReceipt.ClientCode", new SelectList(Html.ClientCodeDebitNoteDropDownList(), "ClientCode", "ClientName", Model.Account_ClientReceipt.ClientCode), new { id = "Account_ClientReceipt.ClientCode", @class = "form-control input-sm" })
                                @Html.ValidationMessageFor(model => model.Account_ClientReceipt.ClientCode, "", new { @class = "text-danger" })
                    <br />

    How do I select the DebitNoteNo and ClientCode values together using one dropdown List rather than two?

    Thanks for your anticipated quick response.


    Monday, November 12, 2018 3:01 PM

All replies

  • User1520731567 posted

    Hi Lawrence_Ajayi,

    Firstly,I do not clear what you want? Multiple choice or single choice?Arrange data sources vertically or horizontally?

    But in general, merging fields is difficult to achieve based on your current code.

    I think you should change the direction,for example:

    1.make a viewmodel which contains two fields.

    2.populate this viewmodel with the data set of these two fields

    ...and so on 

    Best Regards.

    Yuki Tao

    Tuesday, November 13, 2018 10:17 AM
  • User-1244692504 posted

    Thanks Yuki, 

    What I want to do is to have a multiple choice horizontally (on same row) as illustrated in the DropDown List below:

    Debit Note No : DN000000000030 | 0000000004| SUMMAL FOODS LIMITED

    Client Account : 0000000004| SUMMAL FOODS LIMITED

    From the above illustration infront of DebitNoteNo DropDown list,  How do I select DN000000000030, and  0000000004 horizontally. 

    Is this possible please. The second Dropdownlist infront of  Client Account will not be necessary if i could select both on the first Dropdownlist.

    I tried to pass the 0000000004 into a parameter, but its not working.


    I read about the DropDownList base class and I discovered it will only accept a TestField and a Value . Does it mean I can only select one item per each DropDownList?

    The reason why I wanted both DN000000000030, and  0000000004  selected is to ensure the Client ID to which the DebitNoteNo is attached is the one the user selected. 


    If it is not possible, please how do I validate the user selection to ensure the correct Client code selected infront of DebitNoteNo is the same with the one selected infront of Client Account?

    Please illustrate your answer with an example for clarity.

    Your help is greatly appreciated.

    Friday, November 16, 2018 8:33 AM