电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

GridView实现全选及删除源代码


发布日期:2023/7/8
 

前台代码
<asp:templatefieldheadertext="选择"><itemtemplate></itemtemplate><asp:checkboxid="CheckBox"runat="server"></asp:checkbox></asp:templatefield><asp:buttonid="Button"onclick="Button_Click"runat="server"text="全部选中"></asp:button><asp:buttonid="Button"onclick="Button_Click"runat="server"text="删除所选"></asp:button>

后台代码
protectedvoidButton_Click(objectsenderEventArgse){if(ButtonText=="全部选中"){foreach(GridViewRowrowinGridViewRows){CheckBoxCheckBox=(CheckBox)rowCells[]FindControl("CheckBox");CheckBoxChecked=true;}ButtonText="全部不选";}else{foreach(GridViewRowrowinGridViewRows){CheckBoxCheckBox=(CheckBox)rowCells[]FindControl("CheckBox");CheckBoxChecked=false;}ButtonText="全部选中";}}protectedvoidButton_Click(objectsenderEventArgse){foreach(GridViewRowrowinGridViewRows){CheckBoxCheckBox=(CheckBox)rowCells[]FindControl("CheckBox");if(CheckBoxChecked==true){SqlConnectionconn=FunInitConn();SqlCommandcomm=newSqlCommand();commConnection=conn;commCommandText="deletefromCommentwhereComment_ID=’"+rowCells[]Text+"’";connOpen();commExecuteNonQuery();connClose();}}}

上一篇:进程性能计数器已禁用的解决办法

下一篇:sp判断中西混字符串长度