在ASP.NET中怎样删除gridview中checkbox被选中的数据
代码我写的是这个但是功能没有实现希望知道的请快快告诉我我会非常感谢你的protectedvoidImageButton2_Click(objectsender,Image...
代码我写的是这个 但是功能没有实现 希望知道的请快快告诉我 我会非常感谢你的
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
string id;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
ss = (CheckBox)GridView1.Rows[i].FindControl("CheckBox2");
if (ss.Checked)
{
SqlConnection con = new SqlConnection(constr);
con.Open();
id = GridView1.Rows[i].Cells[1].Text.ToString().Trim();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "delete from zbglb where id=@id";
cmd.Parameters.AddWithValue("@id",id);
int j = cmd.ExecuteNonQuery();
if (j > 0)
{
Response.Write("");
}
}
}
} 展开
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
string id;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
ss = (CheckBox)GridView1.Rows[i].FindControl("CheckBox2");
if (ss.Checked)
{
SqlConnection con = new SqlConnection(constr);
con.Open();
id = GridView1.Rows[i].Cells[1].Text.ToString().Trim();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "delete from zbglb where id=@id";
cmd.Parameters.AddWithValue("@id",id);
int j = cmd.ExecuteNonQuery();
if (j > 0)
{
Response.Write("");
}
}
}
} 展开
1个回答
2013-06-16
展开全部
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" Width="700px" DataKeyNames="id" Font-Size="10pt"> protected void del_id()
{
string connstr = ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString;
SqlConnection conn = new SqlConnection(connstr);
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (cbox.Checked == true)
{
string TEMP = "delete from 供货任务表 where ((任务编号 ='" + GridView1.DataKeys[i].Value+"') and (状态='申请'))";
conn.Open();
SqlCommand CMD = new SqlCommand(TEMP.ToString(), conn);
CMD.ExecuteNonQuery();
conn.Close(); }
}
}
{
string connstr = ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString;
SqlConnection conn = new SqlConnection(connstr);
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (cbox.Checked == true)
{
string TEMP = "delete from 供货任务表 where ((任务编号 ='" + GridView1.DataKeys[i].Value+"') and (状态='申请'))";
conn.Open();
SqlCommand CMD = new SqlCommand(TEMP.ToString(), conn);
CMD.ExecuteNonQuery();
conn.Close(); }
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询