我在网格视图中有一个按钮。该按钮位于<HeaderTemplate>
网格视图中。按钮文本是全选。
- 健康)状况:
当我选中 Select All 按钮时,下面的所有复选框都被选中(在网格视图中)。
在那一刻,按钮文本应更改为 Unselected All 并且复选框在网格视图中也未选中。(就像我们在 Yahoo Mail 或 中显示的那样)
如果您想在该按钮中更改名称,请单击:
protected void Button1_Click(object sender, EventArgs e)
{
if(!this.gvw1.Columns[0].HeaderText.ToString().Contains("Un"))
{
this.gvw1.Columns[0].HeaderText="UnSelect All";
}
else
{
this.gvw1.Columns[0].HeaderText="Select All";
}
}
如果您想在复选框 OnCheckedChanged 事件中更改名称
protected void Ck_OnCheckedChanged(object sender, EventArgs e)
{
if(!this.gvw1.Columns[0].HeaderText.ToString().Contains("Un"))
{
this.gvw1.Columns[0].HeaderText="UnSelect All";
}
else
{
this.gvw1.Columns[0].HeaderText="Select All";
}
}
代码与小提琴
$('#ChkSelectAll').click(function () {
if($(this).is(":checked")){
$('.ChkSelect').prop('checked', true);
}else{
$('.ChkSelect').prop('checked', false);
}
});
& 在需要时使用 .val() 函数更改文本
还有一个
<script language="javascript">
$(document).ready(function(){
var chkboxrow = "#<%=gvpub.ClientID%> input[id*='chkSelection']:checkbox";
var chkall =$("input[id$='chkAll']");
$(chkall).change(function(){
$(chkboxrow).each(function()
{
if($(this).is(':checked'))
{
$(this).attr('checked', false);
$(chkall).text('Select All');
}
else
{
$(this).attr('checked', true);
$(chkall).text('Unselect All');
}
});
});
});
</script>
编辑:
对于服务器端,单击按钮
bool toggle = true;
if (Button1.Text == "Check All") {
Button1.Text = "Uncheck All";
} else {
Button1.Text = "Check All";
toggle = false;
}
foreach (checkbox in first column) {
chk.Selected = toggle;
}
注意:尝试使用更新面板或处理回发问题。最好将客户端用于此类功能