Edit – Thanks for your replies so far and sorry for not stating exactly what the problem was. The actual markup code is
<asp:DetailsView ID="dvwSomeDetailsView" runat="server"
AutoGenerateRows="False" DataSourceID="SomeDataSourceID">
<Fields>
<asp:TemplateField HeaderText="SomeText" SortExpression="SomeText">
<EditItemTemplate>
<cc1:Editor ID="txtDescription" runat="server"
Content='<%# Bind("SomeText") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblDescription" runat="server"
Text='<%# Bind"SomeText") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Image" CancelImageUrl="~/img/cancel.png"
EditImageUrl="~/img/edit.png" InsertImageUrl="~/img/insert.png"
UpdateImageUrl="~/img/save.png" ShowEditButton="True" />
</asp:DetailsView>
I’m not too sure whether setting the ShowEditButton property should be removed, but when I tried to do that I still couldn’t set it programmatically.
Now in the code behind file I reduced the Page_Load method to this
protected void Page_Load( object sender, EventArgs e )
{
dvwSomeDetailsView.AutoGenerateEditButton = true;
}
What I want to achieve is that by changing the assignment in the Page_Load method I can hide / show the Edit button, but that does not work. When playing around in the markup file I can make the button show up or hide, but I can never change it from the code behind file.
I also tried to explicitly call dvwSomeDetailsView.DataBind after setting the property, but this also didn’t work. Overriding OnPreRender and placing the code from the Page_Load method in their didn’t do anything to improve this either.
Maybe I’m thinking too complicated – shouldn’t there be an easy way to set programmatically whether the button should / shouldn’t show?
Thanks in advance for any comments.
Gorgsenegger
If the code redacted behind the
contains a call to detailsView.DataBind() (either directly or through Page.DataBind()), then that is your problem. The AutoGenerateEditButton property must be set prior to calling DataBind on the DetailsView.