读书人

在等以次多除

发布时间: 2011-12-26 23:09:59 作者: rapoo

在等,,以下多除,
varchar 值 'GridView1.DataKeys[gvr.DataItemIndex].Value ' 成料型 int 的料行法。

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string connStr = ConfigurationManager.ConnectionStrings[ "BTS "].ConnectionString;
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
DataSet ds = new DataSet();
SqlCommand comm = new SqlCommand();
SqlDataAdapter sqlad = new SqlDataAdapter();
comm.Connection = conn;
comm.CommandText = "select * from bts ";
sqlad.SelectCommand = comm;
//Response.Write(sqlad.SelectCommand.CommandText);
sqlad.Fill(ds, "bts ");
GridView1.DataSource = ds.Tables[ "bts "];
GridView1.DataBind();
}
}
protected void Button3_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox ch = (CheckBox)gvr.FindControl( "ItemCheckBox ");
if (ch.Checked)
{
//Ret2.Text += " <li> GridView1 您选择的是(键值): " + GridView1.DataKeys[gvr.DataItemIndex].Value.ToString();
string connStr = ConfigurationManager.ConnectionStrings[ "BTS "].ConnectionString;
SqlConnection conn = new SqlConnection(connStr);


conn.Open();
DataSet ds = new DataSet();
SqlCommand comm = new SqlCommand();
SqlDataAdapter sqlad = new SqlDataAdapter();
string sql;
sql = "delete from bts where au_id= 'GridView1.DataKeys[gvr.DataItemIndex].Value ' ";
comm.Connection = conn;
comm.CommandText = sql;
comm.ExecuteNonQuery();

}
}
}

protected void CheckAll(object sender, EventArgs e)
{
CheckBox cbx = (CheckBox)sender;
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox ch = (CheckBox)gvr.FindControl( "ItemCheckBox ");
ch.Checked = cbx.Checked;
}
}

[解决办法]
而且在你删除数据的时候,为啥还要定义:
DataSet ds = new DataSet();
SqlDataAdapter sqlad = new SqlDataAdapter();
?????
[解决办法]
sql = "delete from bts where au_id= ' " + GridView1.DataKeys[gvr.DataItemIndex].Value.ToString() + " ' ";

读书人网 >asp.net

热点推荐