如何从linq的结果中选择值 [英] How to select the values from the Result of linq

查看:96
本文介绍了如何从linq的结果中选择值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个gridview,因为我有选中复选框。在选择行并单击更新按钮时,我选择通过linq在gridview中选择的行。在这个选定的linq查询中,我想得到两个列值(SlNO,RefNO)作为结果集。如何通过linq获得这个。这是我从网格中选择所选值的linq代码。



 var result =  from  GridViewRow msgRow  in  grdPrice.Rows 
where ((CheckBox)msgRow .FindControl( chkSelect))。选中
选择 grdPrice.Rows [msgRow.RowIndex];







谢谢

解决方案

您可以使用匿名类型属性来完成任务。请检查以下示例。



  var  result =( from  GridViewRow msgRow < span class =code-keyword> in  grdPrice.Rows 
where ((CheckBox)msgRow.FindContr ol( chkSelect))。选中
选择 new {
SlNO = YourSInoValue,
RefNO = YourRefNOValue,
}。)ToList();


Hi,

I am having a gridview in that I am having select check box. While selecting the rows and clicking the Update button I am selecting the rows which are selected in the gridview through linq. In this selected linq query I want to get the two column values(SlNO,RefNO) as a result set. How to get this one through linq. Here is my linq code for selecting the selected value from the grid.

var result = from GridViewRow msgRow in grdPrice.Rows
                    where ((CheckBox)msgRow.FindControl("chkSelect")).Checked
                    select grdPrice.Rows[msgRow.RowIndex];




Thanks

解决方案

You can use an Anonymous Types properties to do your task.Please check the below sample.

var result = (from GridViewRow msgRow in grdPrice.Rows
                    where ((CheckBox)msgRow.FindControl("chkSelect")).Checked
                    select new {
                                 SlNO=YourSInoValue,
                                 RefNO=YourRefNOValue,
                               }).ToList();


这篇关于如何从linq的结果中选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆