本文介绍了如何选择&amp;取消选中Gridview中的复选框...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 亲爱的先生, 这里我写了代码,但我找不到错误而且无法正常工作。 所以PLZ建议我一个简单的解决方案。 设计页面 < asp:GridView ID = grvStudent runat = server AutoGenerateColumns = False BackColor = 白色 BorderColor = #CC9966 BorderStyle = 无 BorderWidth = 1px CellPadding = 4 > < row style backcolor = 白色 forecolor = #330099 / > < 列 > < asp:TemplateField > < HeaderStyle Horizo​​ntalAlign = 中心 / > < HeaderTemplate > < 表格 > < tr > < td > 全选 < / td > < / tr > < tr > < td > < asp:CheckBox ID = chkboxSelectAll runat = server AutoPostBack = True OnCheckedChanged = chkboxSelectAll_CheckedChanged / > < / td > < / tr > < / table > < / HeaderTemplate > < itemtemplate > < asp:CheckBox ID = chkSelect runat = server / > < / itemtemplate > < / asp:GridView > 代码页 受保护 void chkboxSelectAll_CheckedChanged( object sender,EventArgs e) { CheckBox ChkBoxHeader =(CheckBox)grvStudent.HeaderRow.FindControl( chkboxSelectAll); foreach (GridViewRow row in grvStudent.Rows) { CheckBox ChkBoxRows =(CheckBox)row.FindControl( chkSelect); if (ChkBoxHeader.Checked == true ) { ChkBoxRows.Checked = true ; } else { ChkBoxRows.Checked = false ; } } } 解决方案 最好通过客户端实现此功能。因为如果您有50条记录,并且在每个复选框上单击它会触发服务器端事件,然后选中耗时的复选框。以下是几个可以帮助您的链接: 使用Javascript检查/取消选中GridView中的CheckBox [ ^ ] 检查使用jQuery取消选中ASP.Net GridView中的所有CheckBox [ ^ Dear sir ,Here i have written the code, but I can't find out the error and it is not working.So plz suggest me a easy solution.Design Page <asp:GridView ID="grvStudent" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4"> <rowstyle backcolor="White" forecolor="#330099" /> <columns> <asp:TemplateField> <HeaderStyle HorizontalAlign="Center" /> <HeaderTemplate> <table> <tr> <td> Select All </td> </tr> <tr> <td> <asp:CheckBox ID="chkboxSelectAll" runat="server" AutoPostBack="True" OnCheckedChanged="chkboxSelectAll_CheckedChanged" /> </td> </tr> </table> </HeaderTemplate> <itemtemplate> <asp:CheckBox ID="chkSelect" runat="server" /> </itemtemplate></asp:GridView>Code Pageprotected void chkboxSelectAll_CheckedChanged(object sender, EventArgs e) { CheckBox ChkBoxHeader = (CheckBox)grvStudent.HeaderRow.FindControl("chkboxSelectAll"); foreach (GridViewRow row in grvStudent.Rows) { CheckBox ChkBoxRows = (CheckBox)row.FindControl("chkSelect"); if (ChkBoxHeader.Checked == true) { ChkBoxRows.Checked = true; } else { ChkBoxRows.Checked = false; } } } 解决方案 It is better toimplement this functionality through client side. Because if your has 50 records and on each checkbox click it fires server side event, then check the checkbox which is time consuming. Here are couple of links that may help you:Check/uncheck CheckBox in a GridView using Javascript[^]Check Uncheck all CheckBoxes in ASP.Net GridView using jQuery[^] 这篇关于如何选择&amp;取消选中Gridview中的复选框...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-03 05:00