Avatar of lulu50
lulu50
Flag for United States of America asked on

Split data then list them in the Dropdown list

Hi,

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>
 </select>

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>
</select>

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>
                                    }
                                    else
                                    {
                                        <option value="@data.Value">@data.Text</option>
                                    }
                                }
                            </select>


  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(),
                 })
                .Distinct()
                .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(),
                })
                 .Distinct()
                .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,
.NET MVC* ASP .NET MVC 5C#

Avatar of undefined
Last Comment
lulu50

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
it_saige

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
lulu50

ASKER
saige,

Thank you so much!!!!

I'm learning from you.

Thank you so much!!!!!!

You are the best !!!!!!

Thank you again.
lulu50

ASKER
saige,

YOU ARE THE BEST MY FRIEND AND I THANK YOU FROM ALL MY HEART FOR ALL YOUR HELP !!!

Thank you,
Lulu
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck