我正在尝试隐藏/显示ASP.NET模板中的编辑/保存按钮。因此,我希望编辑按钮在未选中任何行时显示,然后在单击时将其隐藏,然后使保存按钮可见。
如何访问和更新属性?
我尝试过的解决方案只给出了"Null"
我所拥有的:
<ItemTemplate>
<asp:ImageButton ID="ImageButtonEdit" runat="server" CommandName="Edit" ImageUrl="loginstyling/images/Edit.png"/>
<asp:ImageButton ID="ImageButtonUpdate" runat="server" CommandName="Update" ImageUrl="loginstyling/images/Save.png" OnClick="ImageButtonUpdate_Click" Visible="true"/>
<asp:ImageButton ID="ImageButtonDelete" runat="server" CommandName="Delete" ImageUrl="loginstyling/images/Remove.png" visible="false" />
</ItemTemplate>我在后面尝试过:
protected void ImageButtonUpdate_Click(object sender, ImageClickEventArgs e)
{
ImageButton test = (ImageButton)GridView1.FindControl("ImageButtonUpdate");
test.Attributes.Add("Visible", "False");
}发布于 2016-11-29 01:12:24
如果此方法有效,请尝试:
test.Visible = false;发布于 2016-11-29 01:20:49
您确定.FindControl("ImageButtonUpdate");返回一个有效的对象吗?
由于它在另一个post FindControl() return null中返回null检查,这似乎与您遇到的问题相同。
发布于 2016-11-29 01:37:34
尝试为GridView使用RowDataBoundEvent,如果它有效的话:
protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton test = (ImageButton)e.Row.FindControl("ImageButtonUpdate");
test.Visible = false;
}
}https://stackoverflow.com/questions/40849700
复制相似问题