HyperLinkField hl = new HyperLinkField();
hl.HeaderText = "操作";
hl.Text = "查看";
hl.DataNavigateUrlFields = new string[] { "用戶ID" };
hl.DataNavigateUrlFormatString = "UpdateUser.aspx?id={0}";
gvUser.Columns.Add(hl);
CommandField field = new CommandField();
field.ItemStyle.ForeColor = Color.Blue ;
field.DeleteText = "删除";
field.ShowDeleteButton = true;
gvUser.Columns.Add(field);
gvUser.DataSource = dataTable;
gvUser.DataBind();
protected void gvUser_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (DataControlRowType.DataRow == e.Row.RowType)
{
TableCell tableCell = (TableCell)e.Row.Cells[4];
if (Convert.ToInt32(tableCell.Text) == 1)
{
tableCell.Text = "启用";
}
else {
tableCell.Text = "禁用";
}
int row = gvUser.Columns.Count-1;
((LinkButton)(e.Row.Cells[row].Controls[0])).Attributes.Add("onclick", "return confirm('确定要删除吗?')");
}
}
protected void gvUser_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id = Convert.ToInt32(gvUser.DataKeys[e.RowIndex].Value.ToString());
bool result = users.DelteUsers(id);
bool rs = users.DelteUsersValue(id);
if (result && rs)
{
LiteralMenu.Text = "<script>alert('删除成功!')</script>";
Databind();
}
else
{
LiteralMenu.Text = "<script>alert('删除失敗!')<script>";
}
}