婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識(shí)庫 > ASP.NET Gridview 中使用checkbox刪除的2種方法實(shí)例分享

ASP.NET Gridview 中使用checkbox刪除的2種方法實(shí)例分享

熱門標(biāo)簽:萊蕪?fù)夂綦婁N機(jī)器人價(jià)格 凱立德導(dǎo)航官網(wǎng)地圖標(biāo)注 電銷語音自動(dòng)機(jī)器人 戶外地圖標(biāo)注軟件手機(jī)哪個(gè)好用 智能電話營銷外呼系統(tǒng) 地圖標(biāo)注和認(rèn)領(lǐng) 鄭州400電話辦理 聯(lián)通 五常地圖標(biāo)注 長春呼叫中心外呼系統(tǒng)哪家好
方法一:
后臺(tái)代碼:
復(fù)制代碼 代碼如下:

 protected void btn_delete_Click(object sender, EventArgs e)
    {
        for (int i = 0; i this.GridView1.Rows.Count; i++)
        {
            int id = Convert.ToInt32(this.GridView1.DataKeys[i].Value);
            if ((this.GridView1.Rows[i].Cells[0].FindControl("CheckBox1") as CheckBox).Checked == true)
            {
                Delete(id);
                ClientScript.RegisterStartupScript(GetType(),"提示","script>alert('刪除成功!')/script>");
            }
        }
        this.GridView1.DataBind();
    }//刪除
    private void Delete(int id)
    {
        using (SqlConnection conn = new SqlConnection(str))
        {
            conn.Open();
            SqlCommand comm = conn.CreateCommand();
            comm.CommandText = "delete from Notice_Msg where id=@id";
            comm.Parameters.Add(new SqlParameter("@id", id));
            comm.ExecuteNonQuery();
        }
    }

前臺(tái)代碼:
復(fù)制代碼 代碼如下:

asp:GridView ID="GridView1" runat="server" DataKeyNames="id">

另外還得添加一列,讓其綁定的字段為id,并且把這一列的visable屬性設(shè)為false
方法二:
后臺(tái):
復(fù)制代碼 代碼如下:

 protected void btn_delete_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in this.GridView1.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                CheckBox ckb = row.Cells[2].FindControl("CheckBox1") as CheckBox;
                if (ckb.Checked)
                {
                    using (SqlConnection sqlCnn = new SqlConnection(str))
                    {
                        using (SqlCommand sqlCmm = sqlCnn.CreateCommand())
                        {
                            sqlCmm.CommandText = "delete from Regime_Table where id='" + row.Cells[0].Text + "' ";
                            sqlCnn.Open();
                            int a= sqlCmm.ExecuteNonQuery();
                            if (a>0)
                            {
                                ClientScript.RegisterStartupScript(GetType(),"提示","script>alert('刪除成功!')/script>");
                            }
                            else
                            {
                                ClientScript.RegisterStartupScript(GetType(), "提示", "script>alert('刪除失敗!')/script>");
                            }
                            this.DataBind();
                        }
                    }
                }
            }
        }
    }

前臺(tái):
復(fù)制代碼 代碼如下:

style type="text/css">
    .Hidden
    {
        display:none;
    }
    /style>
asp:BoundField DataField="id" HeaderText="編號(hào)" >
                   HeaderStyle CssClass="Hidden" />
                   ItemStyle CssClass="Hidden" />
                   /asp:BoundField>

新增加一列,這一列綁定id字段,并且visable屬性不能為false,否則取不出值來。

checkbox全選功能:
復(fù)制代碼 代碼如下:

script type="text/jscript">
         function change(sender) {
             var table = document.getElementById("GridView1");
             for (var i = 1; i table.rows.length; i++) {
                 table.rows[i].cells[1].getElementsByTagName("input")[0].checked = sender.checked;
             }
         }
    /script>
HeaderTemplate>
      input id="Checkbox2" type="checkbox" onclick="change(this)"/>
             全選
         /HeaderTemplate>

標(biāo)簽:宣城 岳陽 西寧 紅河 西藏 衢州 湖州 福州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP.NET Gridview 中使用checkbox刪除的2種方法實(shí)例分享》,本文關(guān)鍵詞  ASP.NET,Gridview,中,使用,checkbox,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ASP.NET Gridview 中使用checkbox刪除的2種方法實(shí)例分享》相關(guān)的同類信息!
  • 本頁收集關(guān)于ASP.NET Gridview 中使用checkbox刪除的2種方法實(shí)例分享的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 楚雄市| 宁武县| 文安县| 鱼台县| 大足县| 栾川县| 漯河市| 纳雍县| 大埔县| 济宁市| 阜南县| 合作市| 铁岭市| 玛多县| 安康市| 滨州市| 浠水县| 武强县| 塔河县| 三江| 岳西县| 当阳市| 山西省| 宁明县| 竹溪县| 瑞昌市| 韩城市| 尼木县| 沛县| 土默特右旗| 彰化市| 小金县| 开江县| 香港 | 东至县| 河间市| 木兰县| 桑植县| 普定县| 若尔盖县| 二手房|