当前位置:编程学习 > C#/ASP.NET >>

如何通过删除按钮删除gridview选中行

  protected void Button10_Click(object sender, EventArgs e)
        {
            int i = GridView2.SelectedIndex;
            GridView2.DeleteRow(i);
       
         }
这样运行弹出 必须声明标量变量 "@序号" 错误
我刚学这个不久,请各路大侠帮忙~ --------------------编程问答-------------------- 没有这样用过。

在RowDeleting中做吧 --------------------编程问答-------------------- sql string ="删除语句 where xx='"+GridView1.SelectedRow.Cells[1].Text.ToString()+"'" ; --------------------编程问答--------------------


protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            BInfo.Delete(int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString()));
            GRBind();
        }
--------------------编程问答--------------------   for (int i = 0; i < GridView1.Rows.Count; i++)
   {
    if (((CheckBox)GridView1.Rows[i].FindControl("Checkselected")).Checked )
    {
     HiddenField hf  = (HiddenField)GridView1.Rows[i].FindControl("HiddenField1");
     if (hf !=null)
      {
        string id = hf.Value;
       dbhelper.exec("delete * from clientInfomations where clientcountID=" + id);
       }
    }
                
 }

    GridView1.DataSource = dbhelper.search("select * from clientInfomations ");
    GridView1.DataBind(); --------------------编程问答-------------------- 通过for循环选中删除的内容 --------------------编程问答--------------------  private void btndlt_Click(object sender, EventArgs e)
        {
SqlConnection con = new SqlConnection("server=.;database=数据库;uid=sa;pwd=sasa");
            con.Open();
            try
            {
                SqlCommand com = new SqlCommand("Delete from 表名where 主键= '" + dataGridView1.SelectedRows[0].Cells[0].Value.ToString() + "'", con);
                if (dataGridView1.SelectedRows.Count > 0)
                {
                    if (Quess("确认要删除XX[" +dataGridView1.SelectedRows[0].Cells[1].Value.ToString() + "]吗?") == DialogResult.Yes)
                    {
                        com.ExecuteNonQuery();
                        MessageBox.Show("XX信息删除成功!","删除提示");
                        con.Close();
                                            }
                }
                else
                {
 
                }
            }
            catch
            {
                MessageBox.Show("XX信息删除失败!","失败提示");
            }
}
 public static DialogResult Quess(string msg)
        {
            return MessageBox.Show(msg, "XX管理", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        } --------------------编程问答-------------------- protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
  int index=e.RowIndex ;
 int id=int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
  GridViewRow gvr=GridView1.Rows[index];
  str1 = gvr.Cells[1].Text;
}

补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,