1

我有一个gridview,其中boundfield是这样的-

 <asp:BoundField  HeaderText="Approved" />

在此 gridview 的 rowcommand 事件中,我想根据命令名称显示一些文本,例如

protected void gwFacultyStaff_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName.Equals("Yes"))     
    {
        string id = e.CommandArgument.ToString();
        GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer;
        int index = Convert.ToInt32(row.RowIndex);
        GridViewRow rows = gwFacultyStaff.Rows[index];
        rows.Cells[12].Text = "TRUE";     
    }
    else if (e.CommandName.Equals("No"))
    {
        string id = e.CommandArgument.ToString();
        GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer;
        int index = Convert.ToInt32(row.RowIndex);
        GridViewRow rows = gwFacultyStaff.Rows[index];
        rows.Cells[12].Text = "FALSE";
    }
}

但它没有向我显示我想要显示的所需文本。有人可以建议我可能的解决方案吗?

4

1 回答 1

1

而不是BoundField使用 a TemplateField,像这样:

<asp:TemplateField HeaderText="Approved">
    <ItemTemplate>
        <asp:Label id="LabelApproved" runat="server"/>
    </ItemTemplate>
</asp:TemplateField>

现在在您的RowCommand活动中,您可以这样做:

protected void gwFacultyStaff_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName.Equals("Yes"))     
    {
        GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer;
        Label theLabel = row.FindControl("LabelApproved") as Label;
        theLabel.Text = "TRUE";
    }
    else if (e.CommandName.Equals("No"))
    {
        GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer;
        Label theLabel = row.FindControl("LabelApproved") as Label;
        theLabel.Text = "FALSE";
    }
}
于 2013-09-07T04:40:37.333 回答