C#如何实现同一个按钮改变值

C#如何实现同一个按钮改变值
[ 标签:c#, 同一个按钮 ] ╭ァ紅太狼。 2009-05-15 16:10
要实现的是一个开关按钮 点了“开” 这个按钮就会显示“关” 反之 点了“关” 这个 按钮就会显示 “开” 怎么写啊 这个代码
前台:
<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=Button1.Text=="关"?"开":"关";
$乐吧$ 回答采纳率:16.0% 2009-05-15 10:52
您已经评价过!
好:0
您已经评价过!
不好:0
btnOpen.Text=="开"?btnOpen.Text="关":btnOpen.Text="开";

绝对没有问题。。。
ぺ烟抽寂寞 2009-05-15 11:37
您已经评价过!
好:0
您已经评价过!
不好:0
bool bl=false
if(bl==false)
{
Button2.Text = "关";
bl=true;
}
else
{
Button2.Text = "开";
bl=false;
}
阔┽软 2009-05-15 12:50
您已经评价过!
好:0
您已经评价过!
不好:0
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值