DCSIMG
ListItemCollection.SelectedItems Extensions - שלמה גולדברג (הרב דוטנט)

שלמה גולדברג (הרב דוטנט)

מרצה בסלע ויועץ בעולם ה - net.

ListItemCollection.SelectedItems Extensions

 

במידה ואתם צריכים לקבל מאובייקט המכיל ListItemCollection (כמו CheckBoxList ודומיו) את כל הערכים שהמשתמש בחר, תוכלו להשתמש בפונקצייה הבאה
 

public static class ListItemCollectionExtensions

{

    public static IEnumerable<ListItem> SelectedItems(this ListItemCollection collection)

    {

        foreach (ListItem item in collection)

        {

            if (item.Selected)

            {

                yield return item;

            }

        }

    }

 

 
 
בפוסט הבא אני אסביר מה זה ה - yield למי שלא מכיר (זה קיים מ - C#2.0)

תוכן התגובה

Rotem Bloom כתב/ה:

נחמד מאוד.

תודה

# April 17, 2011 2:57 PM

Sasha Goldshtein כתב/ה:

I would use Where instead of reimplementing it :-)

It would also take care of the null check.

# May 1, 2011 10:45 AM
שלח תגובה

(שדה חובה)  

(שדה חובה)  

(אופציונלי)

(שדה חובה) 

Please add 3 and 1 and type the answer here:


Enter the numbers above: