<div>
<asp:Button ID="Button1" runat="server" CommandArgument="fbi" CommandName="sort"
OnCommand="Button1_Command" Text="我是FBI" />
<asp:Button ID="Button2" runat="server" CommandArgument="fu" CommandName="sort" OnCommand="Button1_Command"
Text="我是福尔摩斯" />
<asp:Button ID="Button3" runat="server" CommandArgument="cia" CommandName="ccia"
OnCommand="Button1_Command" Text="我是CIA" />
<asp:Button ID="Button4" runat="server" CommandArgument="cia" CommandName="bande"
OnCommand="Button1_Command" Text="我是邦德" /><br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br />
<br />
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label><br />
<br />
<br />
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label><br />
<br />
代码如下:要注意看,关键在这里啊!
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Command(object sender, CommandEventArgs e)
{
switch (e.CommandName)
{
case "sort":
Sort_Listt((String)e.CommandArgument);
break;
case "ccia":
Label3.Text = "我是一个CIA,帅吧!";
break;
case "bande":
Label4.Text = "我是邦德啊!假的!!";
break;
}
}
void Sort_Listt(string commandArgument)
{
switch (commandArgument)
{
case "fbi":
Label1.Text = "真的!我是一个FBI";
break;
case "fu":
Label2.Text = "假的!我不是福尔摩斯,它已经老死了!!";
break;
}
}