---
title: "Command事件"
author: "ayaya"
date: "2008-12-16T09:21:40Z"
tags: []
slug: "command"
draft: false
lastmod: "2008-12-16T09:21:40Z"
id: 294816
url: "https://ayaya.iteye.com/blog/294816"
---

Button控件使用的是Command事件，该事件可以在【CommandEventArgs e】e中传递CommandName和CommandArgument这两个参数【这两个参数是Button控件的属性】，在你的程序里就是提取了这个参数里的字符串内容。 
protected void Del_Click(object sender, CommandEventArgs e) 
    { 
        string id = e.CommandArgument.ToString(); 
        string sql = "delete from  where id=" + id; 
        SqlHelper ado = new SqlHelper(); 
        if (ado.Excule(sql)) 
        { 
            Response.Write(" <script>alert('删除成功!'); </script>"); 
        } 
        else 
        { 
            Response.Write(" <script>alert('删除失败!'); </script>"); 
        } 
    }