Access footer or header in DataGrid!

I got annoyed that I had to use foreach or use the OnItemCreated event to access the footer. If I can just have a simple form where I add rows, I could integrate the form into the grid by using footer. Why loop when you can access directly?

// Header access

System.Web.UI.Control header = MyDataGrid.Controls[0].Controls[0];

// Footer access

System.Web.UI.Control footer = MyDataGrid.Controls[0].Controls[MyDataGrid.Controls[0].Controls.Count - 1];

// footer.FindControl("Whatever");

// if you know that "Whatever" is a button, and you want to directly access it's Text property:

// ((Button)footer.FindControl("Whatever")).Text;

 

Share this article!

Follow us!

Find more helpful articles: