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
How to Hide GridView Column using Javascript on ButtonClick in asp.net?
提问by SHEKHAR SHETE
I have a GridView
from which i want to Show the GridColumn
on Button Click
.
我有一个GridView
从我想表现GridColumn
的Button Click
。
The
Column
with 'Source
' i want to display on Button click
using 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();"
事件上调用此函数。