Abstract out repeated code

Posted by CookieMonster on Stack Overflow See other posts from Stack Overflow or by CookieMonster
Published on 2010-03-31T16:13:02Z Indexed on 2010/03/31 16:23 UTC
Read the original article Hit count: 370

Filed under:
|

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;
                }

            }


        }

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET