troubleshooting Question

Split data then list them in the Dropdown list

Avatar of lulu50
lulu50Flag for United States of America asked on
3 Comments1 Solution108 ViewsLast Modified:

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>

...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>

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);


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);

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

Thank you so much for your help,
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros