datalist gridview编辑.删除多行

cs部分:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class test_list : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            for (int i = 1; i <=GridView1.Columns.Count; i++)
            {
                DropDownList1.Items.Add(i.ToString());
            }
        }
    }
    protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
    {
        DataList1.EditItemIndex = e.Item.ItemIndex;
        DataList1.DataBind();
    }
    protected void DataList1_CancelCommand(object source, DataListCommandEventArgs e)
    {
        DataList1.EditItemIndex = -1;
        DataList1.DataBind();
      
    }
    protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
    {
        int id = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex]);

        string username = ((TextBox)e.Item.FindControl("TextBox1")).Text;
        string pwd = ((TextBox)e.Item.FindControl("TextBox2")).Text;



        if (DB.exesql("update login set username='"+username+"',userpwd='"+pwd+"' where id="+id) > 0)
        {

           // Response.Write("<script>alert('修改成功!');</script>");

            DataList1.EditItemIndex = -1;

            DataList1.DataBind();

        
        }
    }
    
    protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        int id = Convert.ToInt32(e.Item.ItemIndex);

       if(DB.exesql("delete from login where id="+id)>0)

       {
           DataList1.EditItemIndex = -1;
           DataList1.DataBind();
      
       }
    }
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
      
      
    
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int c = Convert.ToInt32(DropDownList1.SelectedValue)-1;

        GridView1.Columns[c].Visible = false;

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < GridView1.Columns.Count;i++ )
        {
            GridView1.Columns[i].Visible = true;
        }
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
         foreach( GridViewRow dr in GridView1.Rows )
         {
             CheckBox chk = (CheckBox)dr.Cells[3].FindControl("CheckBox2");
             if (!chk.Checked)
             {
                 chk.Checked = true;
             }
             else
             {
                 chk.Checked = false;
            
             }
         }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        foreach( GridViewRow gr in GridView1.Rows  )
        {
            CheckBox chk = (CheckBox)gr.Cells[3].FindControl("CheckBox2");

            if (chk.Checked)
            {
                int UserID = Convert.ToInt32(((HiddenField)gr.Cells[4].FindControl("HiddenField1")).Value);

                DB.exesql("delete from ygb where yg_id=" + UserID);
                GridView1.DataBind();
                Response.Write("删除成功!");
                
            }
        }
    }
}
 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值