雪雨星风 发布留言 2008-6-20 14:39
gridview操作数据问题?超紧急
//前台主要代码
//数据绑定
protected void datebing()
{
try
{
SqlConnection myconn = new SqlConnection(publicclass.getconnstr());
myconn.Open();
string sqlcomm = "select * from UF_OWNERCOMM";
SqlDataAdapter myda = new SqlDataAdapter(sqlcomm, myconn);
DataSet myds = new DataSet();
myda.Fill(myds, "UF_OWNERCOMM");
GridView1.DataSource = myds;
GridView1.DataKeyNames = new string[] { "UF_OWNERCOMM_ID" };
GridView1.DataBind();
myconn.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
//后台删除功能代码
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
string sqlcom = "delete from UF_OWNERCOMM where UF_OWNERCOMM_ID = '" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
SqlConnection myconn = new SqlConnection(publicclass.getconnstr());
myconn.Open();
int i = new SqlCommand(sqlcom, myconn).ExecuteNonQuery();
if (i > 0)
{
Response.Write("");
}
else
{
Response.Write("");
}
myconn.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
datebing();
}
}
//批量删除
protected void Button8_Click(object sender, EventArgs e)
{
string ggID = "";
foreach (GridViewRow row1 in GridView1.Rows)
{
if (((CheckBox)row1.FindControl("checkbox1")).Checked)
{
try
{
ggID = this.GridView1.DataKeys[row1.DataItemIndex].Value.ToString();
SqlConnection myconn = new SqlConnection(publicclass.getconnstr());
myconn.Open();
string sqlcom = "delete from UF_OWNERCOMM where UF_OWNERCOMM_ID = '" + ggID + "'";
SqlCommand mycommand = new SqlCommand(sqlcom, myconn);
mycommand.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
Response.Write("");
datebing();
}
//全选
protected void Button6_Click(object sender, EventArgs e)
{
try
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox ck = (CheckBox)row.FindControl("checkbox1");
if (ck.Checked)
{
ck.Checked = true;
}
else
{
ck.Checked = true;
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
//取消全选
protected void Button7_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox ck = (CheckBox)row.FindControl("checkbox1");
{
if (ck.Checked)
{
ck.Checked = false;
}
else
{
ck.Checked = false;
}
}
}
}冰彩虹 发布留言 2008-6-20 19:23
话都说不清楚...小乌龟 发布留言 2008-6-20 19:48
please show the error information!
页: [1]