gridview操作数据问题?超紧急
//前台主要代码<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" HorizontalAlign="Center" Width="98%" BackColor="White" BorderColor="Blue">
<Columns>
<asp:TemplateField HeaderText="选择">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UF_OWNERCOMM_NAME" DataFormatString="{0:d}" HeaderText="业主姓名" />
<asp:BoundField DataField="UF_OWNERCOMM_LOUPAN" DataFormatString="{0:d}" HeaderText="楼盘名称" />
<asp:BoundField DataField="UF_OWNERCOMM_FLORID" DataFormatString="{0:d}" HeaderText="楼号/名" />
<asp:BoundField DataField="UF_OWNERCOMM_QQ" DataFormatString="{0:d}" HeaderText="QQ号" />
<asp:BoundField DataField="UF_OWNERCOMM_Email" DataFormatString="{0:d}" HeaderText="邮箱" />
<asp:BoundField DataField="UF_OWNERCOMM_PHONE" DataFormatString="{0:d}" HeaderText="电话" />
<asp:BoundField DataField="UF_OWNERCOMM_CKQX" DataFormatString="{0:d}" HeaderText="查看权限" />
<asp:BoundField DataField="UF_OWNERCOMM_TXZID" DataFormatString="{0:d}" HeaderText="加入" />
<asp:BoundField DataField="UF_OWNERCOMM_EXAMINE" DataFormatString="{0:d}" HeaderText="审核状态" />
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:Button ID="Button11" runat="server" Text="审批" />
<asp:Button ID="Button12" runat="server" Text="修改" />
<asp:Button ID="Button13" runat="server" Text="删除" />
</ItemTemplate>
</asp:TemplateField>
//数据绑定
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("<script language=javascript>window.alert('确定要删除吗?')</script>");
}
else
{
Response.Write("<script language=javascript>window.alert('对不起,出现错误?')</script>");
}
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("<script language=javascript>window.alert('确定要删除吗?')</script>");
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;
}
}
}
}