2009年4月21日 星期二

多個Button呼叫同一支Fnuction

將EventArgs 改為 CommandEventArgs 即可直接取值( e.CommandName ; e.CommandArgument)
否則須以方式取值 (((LinkButton)sender).CommandName ; ((LinkButton)sender).CommandArgument)


protected void Button_Command(object sender, CommandEventArgs e) //asign CommandName Artibutes, asign command Events
{
switch(e.CommandName)
{
case "insert":
this.Label1.Text = e.CommandName.ToString();
break;
case "delete":
this.Label1.Text = e.CommandName.ToString();
break;
case "update":
this.Label1.Text = e.CommandName.ToString();
break;
default:
this.Label1.Text = "";
break;
}
}

沒有留言:

張貼留言