Add row to GridView after header row
Posted
by
Jan-Frederik Carl
on Stack Overflow
See other posts from Stack Overflow
or by Jan-Frederik Carl
Published on 2011-01-06T12:48:37Z
Indexed on
2011/01/06
12:54 UTC
Read the original article
Hit count: 291
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)
© Stack Overflow or respective owner