用LINQ获取选中的值

日期:2009-10-30 | 作者: Allen

LINQ绝对是提高开发效率的好工具,下面是在ASP.NET开发中经常会遇到的场景。

1. 获取CheckboxList选中的值。

var itemSelected = CheckboxList.Items.Cast<ListItem>().Where(i => i.Selected)

2. 获取GridView中被选定的行。(假设每一行用CheckBox来选择)

var selectedRows = from GridViewRow msgRow in messagesGrid.Rows
                   where ((CheckBox)msgRow.FindControl("chkUpdateStatus")).Checked
                   select msgRow;

最近比较忙,贴一些没有质量的代码吧,如果您觉得有点用处的话,那真是太好不过。

也许你还会喜欢

3 Responses to “用LINQ获取选中的值”

  1. 1 闯荡博客 十一月 4th, 2009 at 1:29 上午

    闯荡博客,换下链接么?

    回复

  2. 2 IT资讯速客 十一月 4th, 2009 at 7:31 上午

    要了解国外咨询吗?

    回复

  3. 3 les 十一月 4th, 2009 at 7:36 上午

    大家多多交换信息

    回复

Leave a Reply

Additional comments powered by BackType