基于Gridview行的CheckBox选择 [英] CheckBox Selection Based on Gridview Row

查看:77
本文介绍了基于Gridview行的CheckBox选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的GridView看起来像这样..



Hi everybody,

My GridView is look like this..

col1    col2     col3 
1        A        1.2
2        B        3.4
         C        2.3
3        A        2





这里col1是PK列,现在我正在为gridview的每一行做checkBox选择。



javascript:



Here col1 is PK column now i''m doing checkBox selection for each and every row of gridview.

javascript:

function CheckAll(oCheckbox) 
{
    var gdDocument = document.getElementById("<%=gdDocument.ClientID %>");

    for (i = 1; i < gdDocument.rows.length; i++) {
               gdDocument.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = oCheckbox.checked;
    }

}





代码落后:





code behind:

<asp:TemplateField>
      <HeaderTemplate>
             <input id="chkSelect" type="checkbox" onclick="CheckAll(this)"                runat="server" />
      </HeaderTemplate>
       <ItemTemplate>
           <asp:CheckBox ID="chkSelect" runat="server" />
       </ItemTemplate>
</asp:TemplateField>





此代码用于gridview所有行选择。但我希望基于PK列我想显示复选框。



ex:



in row 3没有col1的记录。所以,我不想在那一行显示复选框。





如何做到这一点任何人都可以帮助我.. 。



this code for gridview all rows selection. But i want based upon PK column i want to display the checkBox.

ex:

in row 3 there is no record for col1. so, i don''t want to display checkbox in that row .


How to do this can any one help me...

推荐答案

将网格绑定到该数据后,使用以下代码实现任务



After Binding the grid to that data u cn use following code to achieve ur task

for (int i = 0; i < GridView1.Rows.Count; i++)
       {
           if (GridView1.Rows[i].Cells[0].Text == string.Empty)
           {
               CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
               chk.Visible = false;
           }
       }





享受编码......

玩得开心:)



Enjoy coding ...
have fun :)


使用jQuery可以轻松删除复选框。 ASP.NET Gridview在浏览器中生成标记为HTML表格。通过使用该html表id,您可以使用jquery遍历所有行和列,如下所示。



Using jQuery you can easily remove the checkbox. ASP.NET Gridview generating mark up as HTML table in the browser. By using that html table id you can loop through all rows and cols like below using jquery.


' table#yourTable tr')。each( function (){
var isEmpty = true ;
// 处理每一栏
('table#yourTable tr').each(function(){ var isEmpty = true; // Process every column


这篇关于基于Gridview行的CheckBox选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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