0

我有 N 行和 9 列,其中两列只有在单击图像后才能看到。但是对于每一行,我希望图像只有在该列中有文本时才可见。请帮我。

    <asp:BoundField DataField="Notes" HeaderText="Notes" Visible="False" 
SortExpression="Notes" /> 
<asp:BoundField DataField="Notes" HeaderText="Notes" Visible="False" 
SortExpression="Notes" /> 
<asp:ButtonField ButtonType="Image" ImageUrl="~/Images/Imgs.jpg" 
Text="Button" /> 



 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
GridView1.Columns[2].Visible = true; 
GridView1.Columns[3].Visible = true; 
} 
4

1 回答 1

0

在 RowDataBound 事件中执行此操作:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        var item = (MyType)e.Row.DataItem;
        if (item != null)
        {
            ImageButton button = (ImageButton)e.Row.FindControl("MyButton");
            if (item.Children.Count == 0)
                button.Visible = false;
        }
    }
}
于 2013-05-07T05:51:04.747 回答