1
我想要的刷新类型并不涉及数据本身。如何强制刷新GridView?
这里的情景: 我有3列A,B和C 一个GridView控件,用户可以点击复选框a,b和c键使相应的列可见或不可见。 [要清楚,这些复选框位于gridview外部。]
现在我希望gridview刷新后立即显示每个复选框被单击后选定的列。我该怎么做?
我想要的刷新类型并不涉及数据本身。如何强制刷新GridView?
这里的情景: 我有3列A,B和C 一个GridView控件,用户可以点击复选框a,b和c键使相应的列可见或不可见。 [要清楚,这些复选框位于gridview外部。]
现在我希望gridview刷新后立即显示每个复选框被单击后选定的列。我该怎么做?
假设你有一个表中的每一列(网格),你可以写这样的事情在jQuery的复选框:
$(function() {
$('input:checkbox').change(function() {
//get a reference to the corresponding table column
var $col = $('<#%=grid.ClientID %>' + ' td:nth-child(' + $(this).val() + ')');
if (this.checked) $col.hide();
else $col.show();
});
});
而且相应的复选框有一个值设置为列索引的表。例如:
<input type="checkbox" value="1" /><-- hides first column in grid-->
<input type="checkbox" value="2" /><-- hides second column in grid-->
<input type="checkbox" value="3" /><-- hides third column in grid-->
一个较短/简化版本,也可能会为你工作是这样的:
$(function() {
$('input:checkbox').change(function() {
var $col = $('table ' + 'td:nth-child(' + $(this).val() + ')');
$col.toggle();
});
});
protected void Check_Clicked(Object sender, EventArgs e)
{
CheckBox theOneClicked= (sender as CheckBox);
if(theOneClicked.ID=="checkbox1")
myGrid.Columns[0].Visible=false;
else if(theOneClicked.ID=="checkbox2")
myGrid.Columns[1].Visible=false;
else if(theOneClicked.ID=="checkbox3")
myGrid.Columns[2].Visible=false;
}
我想使用asp.net,这段代码似乎不允许我在后面的C#代码中这样做。我错了吗?谢谢。 – user763554
@ user763554将在几个中添加相同的C#版本。 – Icarus
@ user763554添加了C#版本,但如果我是你,我会在Jquery中执行它,除非只需要隐藏一列 – Icarus