如何在asp.net中更改ButtonField文本

本文关键字:ButtonField 文本 net asp | 更新日期: 2023-09-27 18:07:31

<asp:TemplateField HeaderText="ID" SortExpression="CareerFormID">
                                <ItemTemplate>
                                    <asp:Label ID="CareerFormID" runat="server" Text='<%#Eval("CareerFormID")%>' />
                                </ItemTemplate>
                            </asp:TemplateField>
<asp:BoundField HeaderText="Checked" DataField="checked" />
<asp:ButtonField Text="Edit" CommandName="Select" ButtonType="Link" />
    protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
    string idtemp = (GridView1.SelectedRow.FindControl("CareerFormID") as Label).Text;
    Session["CompanyFormID"] = idtemp;
    Response.Redirect("Management_Edit.aspx");
    //Response.Write(Session["CompanyFormID"]);
}

我想改变ButtonField text="Modify"当DataField="checked"是1,我怎么能做到这一点?

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (e.Row.Cells[4].Text == "1")
        {
            e.Row.Cells[4].Text = "Yes";
            e.Row.Cells[4].ForeColor = System.Drawing.Color.Green;
            e.Row.Cells[6].Text = "Modify";
        }
        else if (e.Row.Cells[4].Text == "0")
        {
            e.Row.Cells[4].Text = "No";
            e.Row.Cells[4].ForeColor = System.Drawing.Color.Red;
        }
    }
}

但这不起作用,单元格[6]文本被更改,但链接被取消。

例如,当我改变文本

时,链接无法工作https://i.stack.imgur.com/L7ugk.jpg

如何在asp.net中更改ButtonField文本

使事件处理程序时DataField="checked"是1(我没有发现它在你的代码,如何使其为1),并做到这一点

//begin of event handler
//check datafield="checked" is 1, I still don't get it this one
 ButtonField.Text="Modify"
//end of event handler