Abstract out repeated code
- by CookieMonster
The code in this event is repeated exactly in two other event handlers. How do I put the repeated code into a method and call that method from the event handlers so I only have to maintain it in one place? I'm not sure how to pass the event args to the calling method.
protected void gvDocAssoc_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((Convert.ToString(DataBinder.Eval(e.Row.DataItem, "DETAIL_TYPE_DESC")) == "Transcript") &&
(Convert.ToString(DataBinder.Eval(e.Row.DataItem, "INSTITUTION_CODE")) == ""))
{
e.Row.BackColor = System.Drawing.Color.Red;
}
if ((Convert.ToString(DataBinder.Eval(e.Row.DataItem, "DETAIL_TYPE_DESC")) == "Certified Diploma") &&
(Convert.ToString(DataBinder.Eval(e.Row.DataItem, "INSTITUTION_CODE")) == ""))
{
e.Row.BackColor = System.Drawing.Color.Red;
}
if ((Convert.ToString(DataBinder.Eval(e.Row.DataItem, "DOC_TYPE_DESC")) == "Post Graduate conditions") &&
(Convert.ToString(DataBinder.Eval(e.Row.DataItem, "INSTITUTION_CODE")) == ""))
{
e.Row.BackColor = System.Drawing.Color.Red;
}
}
}