前台
<asp:TemplateField HeaderText="是否邀约" >
<ItemTemplate>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text='<%# Eval("JL_zhuangtai")%>' />
</ItemTemplate>
</asp:TemplateField>
后台代码
//待邀约按钮变邀约
protected void Button1_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
GridViewRow row = btn.Parent.Parent as GridViewRow;
string a = row.Cells[6].ToString();//获得该按钮所在的单元格
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
sqlcon.Open();
SqlCommand sqlcom;
string sqlstr = "update JianLi set JL_zhuangtai='已邀约' where ID='" + Convert.ToInt32(row.Cells[0].Text) + "'";
sqlcom = new SqlCommand(sqlstr, sqlcon);
sqlcom.ExecuteNonQuery();
sqlcon.Close();
LoadDatas();
}