Add controls dynamically to a listview

I have an listview. The data that populates it is sorted into groups, and i'm using some code in the listview item template, that essentially checks if the grouping field has changed in the data, and if so it prints a new row, with the heading, so it looks a bit like this:

<%# AddGroupingRowIfWPHasChanged() %>

    <tr id="row" class="GridViewRow" runat="server" >
    <td valign="top" align="left"  ><%# Eval("item1") %></td>

This works great. However now I need to add a button the the group heading field, and I can't seem to get this to work. Obvioulsy this button only needs adding if the heading has changed, but the AddGroupingRowIfWPHasChanged() method does not seem to have access to the current ListviewItem, so I can't add a control.

Any suggestions on how I can add a control to a list view dynamically, depandant on whether its a group heading or not?


It may be easier to override the ItemInserting event in the codebehind and do it from there

Use a placeholder?


<asp:Placeholder id="plhControlHolder" runat="server" />


' ** use FindControl if instead a databound event, otherwise you could skip.
Dim plcControlHolder as PlaceHolder = e.Row.FindControl("plcControlHolder") 
Dim btnDynamic As New Button
btnDynamic.Id = "MyButton"

Need Your Help

grouping id with string value instead integer SQL GROUP BY

sql sql-server sql-server-2008 group-by

On Google I just found group by sum (integer value). How can I group by a string value? For the table:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.