页面显示效果为:(即点击编辑后有更新和取消事件)
protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
{
string id = (string) DataList1.DataKeys[e.Item.ItemIndex];
TextBox tb_city = (TextBox)e.Item.FindControl("city");
TextBox tb_state = (TextBox)e.Item.FindControl("state");
TextBox tb_country = (TextBox)e.Item.FindControl("country");
string sql = "update publishers set city='" + tb_city.Text + "',state='" + tb_state.Text + "','country=" + tb_country.Text + "'where pub_id='"+id+"'";
SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=Pubs;Integrated Security=true;");
con.Open();
SqlCommand cmd = new SqlCommand(sql,con);
cmd.ExecuteNonQuery();
DataList1.EditItemIndex = -1;
Bind();
Response.Write("<script>alert('更新成功!')</script>");
con.Close();
}