I have a master page that has a few child pages, this master page happens to contain a grid view because all child pages use one. I've gotten to the stage where I've realized small changes need to be appended to the grid view onrowdatabound event for individual child pages.
As an example I have 3 pages, A.aspx, B.aspx, C.aspx. All three use the grid and bind different data to the gridview that is in the master page. A & B are pretty much identical and there aren't any problems but C wants row attributes to be appended that A & B don't need.
How can I apply these changes without causing problems to the other pages?
[Optional] Is this the complete wrong way to go, and/or should I make them separate pages?
You can bind an event to a GridView programatically. So in page C.aspx you could do something like this:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//find the gridview in the master page
GridView gv = Master.FindControl("GridView1") as GridView;
//add the event to the gridview
gv.RowDataBound += GridView1Master_RowDataBound;
gv.DataSource = mySource;
gv.DataBind();
}
}
protected void GridView1Master_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.BackColor = Color.Red;
}
}