Where I work there is a page with two grid views and both gridviews use the same binding function and there is a problem because of it.. so in the function it has a foreach row for the gridview but it only does it for one gridview as you will see in the code, how can I make it so that it iterates throw the gridviews in the page? therea are two one named GridView1 and the other GridView2, but both use the same data bind. I want to reduce the code.. see below:
protected void GridView_DataBound(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
//somecode related to GridView1
}
foreach (GridViewRow row in GridView2.Rows)
{
//somecode related to GeidView2
}
}
Now the code in each foreach is extensive, and basically is the same code for both cases.. how can i do this more efficiently instead of having the same code in the foreach’s for each one of the gridviews?
Just use the
senderobject that is passed to the event handler. This is a reference to the object that raised the event.