Dynamically adding a Button to a PlaceHolder in a DataGrid
Posted
by
hrnt
on Stack Overflow
See other posts from Stack Overflow
or by hrnt
Published on 2011-01-17T10:50:34Z
Indexed on
2011/01/17
10:53 UTC
Read the original article
Hit count: 191
ASP.NET
I have basically something like this:
<asp:datagrid id="DGrid" runat="server" AutoGenerateColumns="false">
<asp:TemplateColumn HeaderText="Stuff">
<ItemTemplate>
<asp:PlaceHolder id="PH" runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</asp:datagrid>
I need to add a Button to the PlaceHolder depending on the values of the data I am binding. At the moment I am adding the Button after the data is bound in Page_Load. The problem is that the data binding methods are not called in postbacks, so the Button disappears when I click on it.
Any suggestions on how to do this? Problem is that I need to know some attributes of the grid item to create the Button, so I cannot create it before the data has been bound.
© Stack Overflow or respective owner