I´m embracing and extending the GridView Control:
public class MightyGridView : GridView
{
// ...
}
And I would like to add some buttons directly above the GridView:
protected override void OnRowCreated(GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
Parent.Controls.AddAt(Parent.Controls.IndexOf(this) - 1, new LiteralControl("<div>"));
Parent.Controls.AddAt(Parent.Controls.IndexOf(this) - 1, new ImageButton() { ImageUrl = _images[_imageTypes.ShowAllColumns], Width = 16 });
Parent.Controls.AddAt(Parent.Controls.IndexOf(this) - 1, new LiteralControl("</div>"));
This works fine with one tiny, tiny problem: If I have some [br /]´s before the GridView
<asp:Button ID="Button3" runat="server" Text="Button" />
<br /> <!-- This one! -->
<asp:mightygridview
ID="mightyGridView"
runat="server"
AllowSorting="true"
AllowHiding="true"
autogenerateeditbutton="true"
OnRowEditing="mightyGridView_RowEditing"
OnRowCancelingEdit="mightyGridView_RowCancelingEdit"
OnRowUpdating="mightyGridView_RowUpdating">
</asp:mightygridview>
Then the controls were added just after the button and the
(or any other tag) splits my controls and the GridView.
One solution would be to insert my controls into the in which the GridView table is being rendered. So the tag of the GridView is wrapped inside a . But I think I cannot access this generated because it´s no server side control (no runat=”server”). If I could achieve this, my controls and the corresponding GridView could not be seperated.
Any ideas?
Still haven´t found a solution.