如何在 C# 中的 GridViewEdit 中编辑 LinkButton 可见性
我想知道如何在 GridViewEdit 中编辑 LinkButton 的可见性:
我的 aspx 文件中 GridView 的 ItemTemplate 中有一个名为“lbtnActivateConfig”的 LinkButton:
<ItemTemplate>
<asp:LinkButton ID="lbtnActivateConfig" runat="server"
OnClick="GridViewDeactivate" Visible="false">Deaktivieren
</asp:LinkButton>
</ItemTemplate>
现在我想在该方法中更改 LinkButton 的可见性:
protected void GridViewEdit(object sender, GridViewEditEventArgs e)
{
GridViewRow row = this.ConfigGridView.Rows[e.NewEditIndex];
LinkButton buttonActivate = (LinkButton)ConfigGridView.Rows[row.RowIndex].FindControl("lbtnActivateConfig");
buttonActivate.Visible = true;
}
在调试时,它捕获 LinkButton 并似乎设置其可见性。但 LinkButton 仍然不可见。
如果我将按钮更改为在 aspx-File 内可见并尝试在方法中更改它,情况是一样的。
对我来说, aspx-File 似乎总是最后执行并覆盖方法中的更改。这是对的吗?如何更改方法内的可见性?有什么想法吗?
谢谢你,再见!
I wonder how to edit a the visibility of a LinkButton within a GridViewEdit:
I have got a LinkButton named "lbtnActivateConfig" in the ItemTemplate of a GridView in my aspx-File:
<ItemTemplate>
<asp:LinkButton ID="lbtnActivateConfig" runat="server"
OnClick="GridViewDeactivate" Visible="false">Deaktivieren
</asp:LinkButton>
</ItemTemplate>
Now I want to change the visibility of the LinkButton insite this method:
protected void GridViewEdit(object sender, GridViewEditEventArgs e)
{
GridViewRow row = this.ConfigGridView.Rows[e.NewEditIndex];
LinkButton buttonActivate = (LinkButton)ConfigGridView.Rows[row.RowIndex].FindControl("lbtnActivateConfig");
buttonActivate.Visible = true;
}
While debugging it catches the LinkButton an seems to set it's visibility. But the LinkButton is still invisible.
It's the same if I change the button to visible inside the aspx-File and try to change it in the method.
For me it seems that the aspx-File is always executed at last and overwrites the changes in the method. Is this right? How can I change the visibility inside the method? Any ideas?
Thank you and Goodbye!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请尝试以下操作:
您不需要将其转换为
LinkButton
,因为所有控件都具有Visible
属性。当您将 FindControl 设置为变量时,该变量是通过值而不是通过引用设置的,这意味着您没有引用实际的控件。Try the following:
You don't need to cast it as
LinkButton
because all controls have theVisible
property. And when you setFindControl
to a variable, the variable is set by value rather than by reference which means you aren't referring to the actual control.