绑定时如何取消选择复选框 [英] how to unselect the checkbox while binding

查看:115
本文介绍了绑定时如何取消选择复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的应用程序中,我正在使用gridview,因为我正在使用复选框.将数据绑定到gridview时,我想取消选中所有复选框.谁能帮我解决这个问题.

谢谢

Hi,

In my application I am using the gridview in that I am using the check box. While binding the data into the gridview I want to unselect all the check boxes. Can any one help me to solve this problem.

Thanks

推荐答案

//you can do as below

protected void gridview_RowDataBound(object sender, GridViewRowEventArgs e)
             {
                 if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox chk = (CheckBox)e.Row.FindControl("chktest");
                    chk.Checked = false;
                }
             }


如果找到的内容标记为解决方案


mark as solution if its what you are finding


row_databound 事件中,您需要使用 findcontrol()方法搜索gridviewrow中的复选框然后取消选中它们.
或者,您可以使用以下代码.
In row_databound event you need to use findcontrol() method to search checkboxes in gridviewrow and then uncheck them.
OR you can use following code.
(row.Cells[CheckBoxColumn.Index] as DataGridViewCheckBoxCell).value = false;


您将复选框列绑定到什么值?

如果是布尔值,请确保在数据源中将所有值都设置为false.

如果未绑定任何值,请确保已在复选框标记中设置了Checked="False".

HTH!

Dinesh

如果这可以解决您的问题,请标记为解决方案!
What value are you binding the checkbox column to??

If it is a bool then ensure that all values are set to false in the data source.

If you are not binding any value then ensure that you have set the Checked="False" in the checkboxes markup.

HTH!

Dinesh

Mark as solution if this solved your problem!


这篇关于绑定时如何取消选择复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆