任何其他方式可以取消选中整个列 [英] any other way to uncheck the entire col

查看:137
本文介绍了任何其他方式可以取消选中整个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.cs

.cs

protected void grdVPlayer_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {   if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox objCheck = new CheckBox();
             
                    objCheck = (CheckBox)e.Row.FindControl("chkPlayer");
                    objCheck.ID = "chk" + e.Row.RowIndex.ToString();

                    // RB for captain
                    RadioButton OBjWicketkeeper = new RadioButton();// RB for W.keeper
                    RadioButton ObjrbVC = new RadioButton();
                    RadioButton ObjrbCaptain = new RadioButton();

                    OBjWicketkeeper = (RadioButton)e.Row.FindControl("rbWk");
                    OBjWicketkeeper.ID = "WK" + e.Row.RowIndex.ToString();
                    OBjWicketkeeper.InputAttributes.Add("disabled", "true");

                    
                    ObjrbVC = (RadioButton)e.Row.FindControl("rbVcaptain");
                    
                    ObjrbVC.ID = "RBVC" + e.Row.RowIndex.ToString();
                    ObjrbVC.GroupName = "MyGroup";
                    ObjrbVC.InputAttributes.Add("disabled", "true");

                    ObjrbCaptain = (RadioButton)e.Row.FindControl("rbcaptain");
                    ObjrbCaptain.ID = "RBC" + e.Row.RowIndex.ToString();
                    ObjrbCaptain.GroupName = "MyGroup";
                    ObjrbCaptain.InputAttributes.Add("disabled", "true");
                    
                   
             
                    ObjrbCaptain.Attributes.Add("onclick", "CheckClickforCaptain(this," + e.Row.ClientID + ",'" + ObjrbCaptain.ClientID + "','" + ObjrbVC.ClientID + "')");
         
}}


js


js

function CheckClickforCaptain(objCaptain, rowCap, CaptainRButton, ViceCaptainRButton)
       {

          var gridView = document.getElementById("<%=grdVPlayer.ClientID %>");
          var totalrowsingrid = gridView.rows.length;

          if (objCaptain.checked) {
              if (Captain == '')       //display captain
              {
                  Captain = rowCap.cells[2].innerText;  // display captain name
                  alert(Captain);
              }
              else // (Captain != '')  //if captain is already decided then ....
              {

                  var confirmVariable = confirm("Do You Want to change the Captain which you have decided !");
                  if (confirmVariable == true) {
                      alert("You Press Ok!");
                      alert("Captain=" + Captain + "ViceCaptain=" + ViceCaptain);


                          for (var i = 0; i < totalrowsingrid - 1; i++) {
                          var j = 2 + i;
                          if (j < 10) {
                              var ClientID = "ctl00_MainContentPlaceHolder1_grdVPlayer_ctl0" + j + "_RBC" + i;
                          }
                          else {
                              var ClientID = "ctl00_MainContentPlaceHolder1_grdVPlayer_ctl" + j + "_RBC" + i;
                          }
                          //  ClientID.checked=false;
                          document.getElementById(ClientID).checked = false;


注意:我需要其他方法来取消选中没有此网格视图的整个网格视图


Note: I need any other way to uncheck the entire coloumn of the gridview without this

for (var i = 0; i < totalrowsingrid - 1; i++) {
                             var j = 2 + i;
                             if (j < 10) {
                                 var ClientID = "ctl00_MainContentPlaceHolder1_grdVPlayer_ctl0" + j + "_RBC" + i;
                             }
                             else {
                                 var ClientID = "ctl00_MainContentPlaceHolder1_grdVPlayer_ctl" + j + "_RBC" + i;

推荐答案


您可以尝试此链接选中数据网格中的所有复选框 [ ^ ]

我很久以前就将其发布为技巧和窍门",请尝试一下.
Hi
You can try this link Select all checkbox in the data grid[^]

I posted this as Tips and Trick long ago, Try it.


您可以执行以下操作:
You could do something like this:
for (var i = 0; i < totalrowsingrid - 1; i++) {
  var ClientID = "ctl00_MainContentPlaceHolder1_grdVPlayer_ctl" + (j < 10 ? ''0'' : '''') + 2 + i + "_RBC" + i;
}



如果您有空余时间,您还可以研究jQuery,这可以大大简化您的代码.

祝你好运!



If you have some spare time you could also look into jQuery, that could simplify your code a lot.

Good luck!


这篇关于任何其他方式可以取消选中整个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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