熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

GridView實現全選及刪除源代碼

2013-11-13 10:38:48  來源: .NET編程 

  前台代碼
<asp:templatefield headertext="選擇"> <itemtemplate></itemtemplate><asp:checkbox id="CheckBox" runat="server"></asp:checkbox></asp:templatefield><asp:button id="Button" onclick="Button_Click" runat="server" text="全部選中"></asp:button><asp:button id="Button" onclick="Button_Click" runat="server" text="刪除所選"></asp:button>

後台代碼
protected void Button_Click(object sender EventArgs e) { if (ButtonText == "全部選中") { foreach (GridViewRow row in GridViewRows) { CheckBox CheckBox = (CheckBox)rowCells[]FindControl("CheckBox"); CheckBoxChecked = true; } ButtonText = "全部不選"; } else { foreach (GridViewRow row in GridViewRows) { CheckBox CheckBox = (CheckBox)rowCells[]FindControl("CheckBox"); CheckBoxChecked = false; } ButtonText = "全部選中"; } } protected void Button_Click(object sender EventArgs e) { foreach (GridViewRow row in GridViewRows) { CheckBox CheckBox = (CheckBox)rowCells[]FindControl("CheckBox"); if (CheckBoxChecked == true) { SqlConnection conn = FunInitConn(); SqlCommand comm = new SqlCommand(); commConnection = conn; commCommandText = "delete from Comment where Comment_ID=’" + rowCells[]Text + "’ "; connOpen(); commExecuteNonQuery(); connClose(); } } } 


From:http://tw.wingwit.com/Article/program/net/201311/14213.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.