gpt4 book ai didi

c# - Gridview:根据同一行中单元格的值更改链接按钮文本

转载 作者:太空宇宙 更新时间:2023-11-03 21:34:00 25 4
gpt4 key购买 nike

下面是我想要的gridview,ID,NameStatus是Label,Action是链接按钮

ID ------------ 名称 ------------ 状态 ------------ 操作

1 -------------- Name1 ---------- 激活 ---------- 禁用

2 -------------- Name2 ---------- 未激活 ---------- 启用

3 -------------- Name3 ---------- 激活 ---------- 禁用

如何根据 Status 的值(文本)将 LinkBut​​ton 文本设置为“Disable”或“Enable(总是有效无效)?

我的链接按钮如下,如何将文本'Do you want to proceed'更改为'Do you want to Disable' or 'Do you want to Enable' 基于以上逻辑

<asp:LinkButton ID="lbtAction" runat="server"
CommandArgument='<%# Eval("ID")%>'
OnClientClick="return confirm('Do you want to proceed?')"
OnClick="DoAction"></asp:LinkButton>

最佳答案

使用 RowDataBound 并将您的逻辑放在那里:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lbtAction = (LinkButton) e.Row.FindControl("lbtAction");
Label lblStatus = (Label) e.Row.FindControl("lblStatus");
bool active = lblStatus.Text == "Active";
lbtAction.Text = active ? "Disable" : "Enable";
string onClientClick = string.Format("return confirm('Do you want to {0}?')",
active ? "Disable" : "Enable");
lbtAction.OnClientClick = onClientClick;
}
}

关于c# - Gridview:根据同一行中单元格的值更改链接按钮文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22717851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com