C#如何实现同一个按钮改变值
要实现的是一个开关按钮 点了“开” 这个按钮就会显示“关” 反之 点了“关” 这个 按钮就会显示 “开” 怎么写啊 这个代码
前台:
<asp:GridView ID="GridView1" runat="server" onrowcommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="开" CommandName="up" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后台:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "up")
{
if (((Button)sender).Text == "开")
{
((Button)sender).Text = "关";
}
else if (((Button)sender).Text == "关")
{
((Button)sender).Text = "开";
}
}
}
在Button的点击事件中添加代码
if(Button1.Text == "开")
{
Button2.Text = "关";
}
else
{
Button2.Text = "开";
}
继续追问: 不不 就一个按钮 就一个btnOpen 在里面同时要有开和关
补充回答: if(Button1.Text == "开")
{
Button1.Text = "关";
}
else
{
Button1.Text = "开";
}
打错数字了不好意思
{
Button1.Text = "关";
}
else
{
Button1.Text = "开";
}
打错数字了不好意思
Button1.Text=Button1.Text=="关"?"开":"关";
$乐吧$
回答采纳率:16.0%
2009-05-15 10:52
ぺ烟抽寂寞
2009-05-15 11:37