Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Lee 1130 posts 3088 karma points
    Nov 27, 2010 @ 13:39
    Lee
    0

    Passing CheckboxList Values To List<T>

    Ok so its not exactly an Umbraco API problem, but I am using Umbraco to build the site AND this is using Linq2Umbraco.

    I have a GridView which I have a List<T> bound to using Linq2Umbraco - I want to be able to allow filter of the data based on multiple CheckBoxLists.

    For arguments sake let's say I have a List of Jobs, and I want to filter the jobs by a code - So I would have a CheckBoxList like

    • C#
    • ASP.NET
    • php
    • F#
    • etc..

    If someone selects multiple codes, how do you pass the values into a List to rebind to the GridView? Is there a way to pass values as an array? Or maybe a comma separated string? Or do you have to loop through manually?

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Nov 29, 2010 @ 00:32
    Tim
    1

    If you want to get all the selected values of a list, you can use a cunning bit of linq to get them all:

    IEnumerable<string> selectedBits = from ListItem item in YourListObjectNameHere.Items
                                                  where item.Selected
                                                  select item.Value;

    Then to get it as a comma separated string say:

    category.IncludedManufacturers = string.Join(",", selectedBits .ToArray());

    :)

Please Sign in or register to post replies

Write your reply to:

Draft