在每条记录后有个,按钮,点击按钮的时候得到这条记录的id,id是GridView的DataKeyName。
怎么得到呢?

解决方案 »

  1.   

    protected void btnDele_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow row in GridView1.Rows)
            {
                CheckBox ck = (CheckBox)row.FindControl("CheckBox");
                if (ck.Checked)
                {
                    strid = GridView1.DataKeys[row.RowIndex].Value.ToString();
                }
                string sql = "delete from cwpayi where id='" + strid + "'";
                SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["connectionString"]);
                SqlCommand cmd = new SqlCommand(sql, conn);
                conn.Open();
                //cmd.ExecuteNonQuery();
                cmd.Dispose();
                conn.Close();
            }
            //从定向到页面。
            Response.Write("<script language='javascript'>window.parent.mainFrame.location.href='feeDetail.aspx';</script>");
        }
      

  2.   

    DataKey dk = GridView1.SelectedDataKey;
      string ss = dk.Value.ToString();
      

  3.   

    上面的写在SelectedIndexChanged事件里
      

  4.   

    GridView1_RowCommand在这个事件中