简体   繁体   中英

Find Items in Listbox from a collection and select them

Hi I am new to Linq and had a question. I have a Listbox on my page with a checkbox list with products. In my codebehind when i bind my telerik Grid I want to find all products for that Order and select them. What is the best way to go through the list and select items in the Listbox? Please show with some code example? Thanks for your help

int orderId = ((Order)e.Item.DataItem.OrderId);
RadListBox chkProductList = (RadListBox)editItem.FindControl("chkProductList");

List<Product> orderProductList = orderBL.FindProductsinOrder(orderId)

This might not be exact, but you should be able to do something like this:

orderProductList.ForEach(x => chkProductList.Items.FindByValue(x.ToString()).Selected = true);

After doing a little research on the CheckedListBox , I think this is what you need:

orderProductList.ForEach(x => 
    chkProductList.SetItemChecked(chkProductList.Items.IndexOf(x.ToString()), true));

EDIT

Using the RadListBox control for ASP.NET AJAX, you can select an item by value like this:

orderProductList.ForEach(x => 
    chkProductList.FindItemByValue(x.ToString()).Selected = true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM