0

N 行と 9 列があり、画像をクリックした後にのみ 2 つの列が表示されます。しかし、各行について、その列にテキストがある場合にのみ画像が表示されるようにします。私を助けてください。

    <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 に答える