欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp.net下gridview 批量刪除的實(shí)現(xiàn)方法第2/3頁(yè)

 更新時(shí)間:2007年11月22日 23:26:39   作者:  

3 點(diǎn)擊“刪除選中”按鈕的事件。
復(fù)制代碼 代碼如下:

protected void Button1_Click(object sender, EventArgs e) 

    string sqlText = "("; 
    for (int i = 0; i < GridView1.Rows.Count; i++) 
    { 
        //搜索第n行3列 
        CheckBox cbx = (CheckBox)GridView1.Rows[i].FindControl("cbxId"); 
        if (cbx.Checked == true) 
        { 
           sqlText = sqlText + Convert.ToInt32(GridView1.DataKeys[i].Value) + ","; 
        } 
    } 
    //去掉最后的逗號(hào),并且加上右括號(hào) 
    sqlText = sqlText.Substring(0,sqlText.Length - 1) + ")"; 
    sqlText = "delete vote where vote_id in" + sqlText; 
    try 
    { 
        //執(zhí)行刪除語(yǔ)句 
        SqlConnection conn = getCon(); 
        conn.Open(); 
        SqlCommand cmd = new SqlCommand(sqlText,conn); 
        int delCount = Convert.ToInt32(cmd.ExecuteNonQuery()); 
        Response.Write("<script>alert('共刪除" + delCount + "條數(shù)據(jù)');</script>"); 
        dataInit(); 

    } 
    catch(Exception ex) 
    { 
        //若有錯(cuò)誤發(fā)生,輸出錯(cuò)誤信息 
        Response.Write(ex.Message); 
    } 

這里解釋下:SQL語(yǔ)句刪除這里使用的是: delete vote where vote_id in(1,3,5,6)
所以對(duì)于選中后,我們只需要取得(1,3,5,6)這樣的語(yǔ)句就可以了??瓷厦娲a,我稍微做了下注釋。

相關(guān)文章

最新評(píng)論