We help IT Professionals succeed at work.
Get Started

Split data then list them in the Dropdown list

lulu50 asked
Last Modified: 2020-03-02

I have a dropdown list that list the following data like this. This is the output that I have right now.

<select name="CommitIDListID" class="btn btn-default dropdown-toggle" id="CommitIDListID" multiple="multiple">
    <option value="345456456, 553564646">345456456, 553564646</option>
    <option value="353434534">353434534</option>
    <option value="535443335, 756555666, 755444566">535443335, 756555666, 755444566</option>
    <option value="577543332">577543332</option>
    <option value="755444566">755444566</option>

Open in new window

...but I want the output to be like this

<select name="CommitIDListID" class="btn btn-default dropdown-toggle" id="CommitIDListID" multiple="multiple">
    <option value="553564646">553564646</option>
    <option value="345456456">345456456</option>
    <option value="353434534">353434534</option>
    <option value="535443335">535443335</option>
    <option value="577543332">577543332</option>
    <option value="755444566">755444566</option>   // my data will be distinct because I have two records of the same commit ID
    <option value="756555666">756555666</option>

Open in new window

This is the code that I have right now:

<select multiple="multiple" id="CommitIDListID" name="CommitIDListID" class="btn btn-default dropdown-toggle">
                                @foreach (var data in Model.CommitIDList)
                                    if (data.Selected)
                                        <option value="@data.Value" selected="selected">@data.Text</option>
                                        <option value="@data.Value">@data.Text</option>

  public IEnumerable<SelectListItem> GetAllCommitIDList()
            var GetCommitID = _unitOfWorkCABusinessRules.RuleDetailRepo.GetAll().GroupBy(x => x.CommitID).Select(y => y.First()).Distinct();

            return GetCommitID
                 .Select(x => new SelectListItem
                     Text = x.CommitID,
                     Value = x.CommitID.ToString(),
                .OrderBy(x => x.Text);


Open in new window

This is the code that I'm working on; I know my syntax is wrong:

var CommitIDData = _unitOfWorkCABusinessRules.RuleDetailRepo.GetAll().Select(g => g.CommitID = string.Join(", ", g.CommitID)).Distinct();
   return CommitIDData 
                .Select(g => new SelectListItem
                    Text = g.CommitID,
                    Value = g.CommitID.ToString(),
                .OrderBy(g => g.Text);

Open in new window

My table looks like this: table "RuleDetail"

RuleDetailId    Version         Environment     CQTicket        CommitID
16              Version33	    SIT	            ENT19293	    353434534
17              Version22	    SIT	            ENT95837	    345456456, 553564646
18              version 5	    SIT	            ENT8374	        535443335, 756555666, 755444566
19              version 10	    SIT	            ENT89484	    577543332
20              version25	    SIT	            CQ ticket 55	755444566
21              Version11	    SIT	            ENT00222222

Open in new window

Thank you so much for your help,
Watch Question
Distinguished Expert 2019
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE