using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page 
{
    SqlConnection sqlcon;
    SqlCommand sqlcom;
    string ConStr = "server=(local);user id=myzf;pwd=123456;database=SQL_Data";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            sqlcon = new SqlConnection(ConStr);
            string SqlStr = "select * from 仓库";
            SqlDataAdapter ada = new SqlDataAdapter(SqlStr, sqlcon);
            sqlcon.Open();
            DataSet ds = new DataSet();
            ada.Fill(ds);
            GridView2.DataSource = ds;
            GridView2.DataKeyNames = new string[] { "仓库号" };
            GridView2.DataBind();
            sqlcon.Close();
        }
    }
    protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string sqlstr = "delete from 仓库 where 仓库号='" + GridView2.DataKeys[e.RowIndex].Value.ToString() + "'";
        sqlcon = new SqlConnection(ConStr);
        sqlcom = new SqlCommand(sqlstr, sqlcon);
        sqlcon.Open();
        sqlcom.ExecuteNonQuery();
        sqlcon.Close();
        sqlcon.Open();
        string SqlStr = "select * from 仓库";
        SqlDataAdapter ada = new SqlDataAdapter(SqlStr, sqlcon);
        DataSet ds = new DataSet();
        ada.Fill(ds);
        GridView2.DataSource = ds;
        GridView2.DataKeyNames = new string[] { "仓库号" };
        GridView2.DataBind();
        sqlcon.Close();

    }
    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ((LinkButton)(e.Row.Cells[4].Controls[0])).Attributes.Add("onclick", "return confirm('确定要删除吗？')");
        }
    }
}
