javascript 如何在asp.net 中的ButtonClick 上使用Javascript 隐藏GridView 列?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21452582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 20:56:50  来源:igfitidea点击:

How to Hide GridView Column using Javascript on ButtonClick in asp.net?

javascriptgridviewvisibilityshow-hide

提问by SHEKHAR SHETE

I have a GridViewfrom which i want to Show the GridColumnon Button Click.

我有一个GridView从我想表现GridColumnButton Click

enter image description hereThe Columnwith 'Source' i want to display on Button clickusing Javascript.

在此处输入图片说明Column与“ Source”我想显示在Button click使用Javascript

Note:The Button that we click to visible the column is outside the GridView.

注意:我们单击以显示该列的 Button 在 GridView 之外。

<asp:TemplateField HeaderText="Source" ItemStyle-Width="50px" ItemStyle-HorizontalAlign="Center"
    HeaderStyle-HorizontalAlign="Center">
    <ItemTemplate>
 <asp:Button ID="BtnSource" runat="server" CausesValidation="false" OnClick='<%# "return SetRowValues("+Eval("ttppcid")+",this.id,"+Eval("Fair")+","+Eval("Good")+","+Eval("Mint")+","+Eval("Poor")+","+Eval("Broken")+")"%>' Text="Source" />
  </ItemTemplate>
</asp:TemplateField>

Help Appreciated!

帮助赞赏!

回答by Manish Sharma

try this,

试试这个,

Add JavaScript in your page.

在您的页面中添加 JavaScript。

<script type="text/javascript">
    function hideColumn() {
        var gridrows = $("#GridView1 tbody tr");

        for (var i = 0; i < gridrows.length; i++) {
            gridrows[i].cells[1].style.display = "none";
        }
        return false;

    };
</script>

cells[1]instead of you can use your column number. and call this function on OnClientClick="Javascript:return hideColumn();"event.

cells[1]而不是您可以使用您的列号。并在OnClientClick="Javascript:return hideColumn();"事件上调用此函数。