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 i开发者_运维知识库deas?
Thank you and Goodbye!
Try the following:
protected void GridViewEdit(object sender, GridViewEditEventArgs e)
{
GridViewRow row = this.ConfigGridView.Rows[e.NewEditIndex];
(ConfigGridView.Rows[row.RowIndex].FindControl("lbtnActivateConfig")).Visible = true;
}
You don't need to cast it as LinkButton
because all controls have the Visible
property. And when you set FindControl
to a variable, the variable is set by value rather than by reference which means you aren't referring to the actual control.
精彩评论