简体   繁体   中英

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?

the javascript (should it needed):

      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.

Use a css class with display:none and see if it helps.

A sample css class would look like this:

.classHiddden
 {display:none;}

Then assign this class to the control you want to hide.

Thanks,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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