Add row to GridView after header row
- by Jan-Frederik Carl
I have a GridView with a header and some rows and want to add another row just
below the header using jQuery.
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" ShowHeader="true" runat="server">
<Columns>
<asp:TemplateField HeaderText="Activity Name">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button Text="Add Activity" runat="server" OnClientClick="addActivity(); return false;" />
</div>
</form>
My tries were
$('#GridView1 tbody').prepend('<tr><td>new activity</td></tr>');
Puts a new row above the header
$('#GridView1 table tr:first').after('<tr><td>new activity</td></tr>');
Does nothing (at least nothing visible, as well with any other tr element)