简体   繁体   English

如何正确隐藏datagridview中的列

[英]how to hide column in datagridview properly

here I am trying to hide the column in the datagrid, the column is: 在这里,我试图将列隐藏在数据网格中,该列是:

<asp:BoundField HeaderText="Transaction Category ID" DataField="TransactionCategoryID"
   ItemStyle-CssClass="gridview_item_center" visible="false"/>

but the problem is, when I try to get the data (in javascript function below), while the datagrid column is hidden it acts like it doesn't exist, so the value returned is wrong, is there any alternate solution to just simply hide the column but the value is still acceptable? 但是问题是,当我尝试获取数据时(在下面的javascript函数中),当datagrid列被隐藏时,它的行为就像它不存在,因此返回的值是错误的,是否有任何其他解决方案可以简单地隐藏列,但该值仍然可以接受?

the javascript (should it needed): javascript(需要):

      function ShowAddDialog(lnkTransactionID) {
      if (lnkTransactionID != null) {
          //alert("ID:" + $(lnkTransactionID)[0].innerHTML);

          var td = lnkTransactionID.parentElement;
          var transactionCategory = $(td.nextSibling)[0].innerHTML;
          var transactionDesc = $(td.nextSibling.nextSibling.nextSibling)[0].innerHTML;

          $("[id$='lblTransactionID']").text($(lnkTransactionID)[0].innerHTML);
          $("[id$='hfTransactionID']").val($(lnkTransactionID)[0].innerHTML);
          $("[id$='ddlTransactionCategoryInput']").val(transactionCategory);
          $("[id$='txtTransactionDescInput']").val(transactionDesc);
      }
      $("#divDialog").dialog("open");
  }

When you set the visibility to false, it doesn't get rendered in HTML, hence the error. 将可见性设置为false时,它不会以HTML呈现,因此会出错。

Use a css class with display:none and see if it helps. 将CSS类与display:none一起使用,看看是否有帮助。

A sample css class would look like this: 一个示例CSS类如下所示:

.classHiddden
 {display:none;}

Then assign this class to the control you want to hide. 然后将此类分配给要隐藏的控件。

Thanks, 谢谢,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM