学习

我有俩表
table1  filed1  filed2
        1        22
        2        2323
        3        343
        4        2323
table2  filed1  filed2
        1        22
        3        343


通过  gridview 绑定 table1 和 checkbox  并且 让gridview中的checkbox 根据table2 默认选中(即table2中有的行默认选中)


最简单、方便的方法就是通过SQL查询返回DataTable,比如:
select a.*,IsExists=case when exists(select 1 from table2 where filed1=a.filed1 and filed2=filed2) then 1 else 0 end
from table1 a
该SQL语句返回结果将是:
      filed1  filed2  IsExists
        1        22      1
        2        2323    0
        3        343      1
        4        2323    0

============================

select a.field1,a.field2,cast(case when b.field1 is null then 0 else 1 end as bit) as state from table1 a
   
left join table2 b on b.field1=a.field1

结果:
field1      field2      state
----------- ----------- -----------
1          22          1
2          2323        0
3          343        1
4          2323        0
直接绑定state
<Columns>
<asp:CheckBoxField DataField="state" />
</Columns>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值