功能:選中CheckBox,后從數(shù)據(jù)庫中刪除選中項(xiàng)。文章側(cè)重將如何實(shí)現(xiàn)批量刪除,對于如何鏈接數(shù)據(jù)庫和綁定數(shù)據(jù)不做詳細(xì)解釋。
1 我們先要在GridView中添加一列為CheckBox。代碼如下:
代碼如下:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="vote_id" HeaderText="編號" />
<asp:BoundField DataField="vote_name" HeaderText="名稱" />
<asp:TemplateField HeaderText="選擇">
<ItemTemplate>
<asp:CheckBox id="cbxId" runat="Server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
注意id為cbxId,呆會(huì)我們要用到。
2 綁定數(shù)據(jù)。
代碼如下:
//初始化數(shù)據(jù)
private void dataInit()
{
string sqlText = "select * from vote";
SqlConnection conn = getCon();
SqlDataAdapter da = new SqlDataAdapter(sqlText,conn);
DataSet ds = new DataSet();
conn.Open();
da.Fill(ds, "vote");
GridView1.DataSource = ds;
GridView1.DataKeyNames = new string[]{"vote_id"};
GridView1.DataBind();
conn.Close();
conn.Dispose();
}
123下一頁閱讀全文
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com