gpt4 book ai didi

c# - 更改gridview的按钮文本

转载 作者:行者123 更新时间:2023-11-30 22:30:08 25 4
gpt4 key购买 nike

我有一个 GridView ,它在模板字段中包含一个按钮。我想在按钮单击事件完成时更改按钮文本。谁能给我一个示例代码。

提前致谢

最佳答案

下面是一段使用 GridView 的 RowCommand() 的代码示例。

ASPX

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" onrowcommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbl1" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="MYCOMMAND" Text="My Text!" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

C#

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<string> lst = new List<string>() { "asd", "xxx" };
GridView1.DataSource = lst;
GridView1.DataBind();
}
}

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "MYCOMMAND")
{
Button Button1 = (Button)e.CommandSource;
if (Button1 != null)
Button1.Text = "changed text..";
}
}

关于c# - 更改gridview的按钮文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9851577/

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