小编Coo*_*ter的帖子

摘要重复代码

此事件中的代码完全在另外两个事件处理程序中重复.如何将重复的代码放入方法并从事件处理程序调用该方法,因此我只需将其保存在一个位置?我不确定如何将事件args传递给调用方法.

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

            }


        }
Run Code Online (Sandbox Code Playgroud)

c# asp.net

0
推荐指数
1
解决办法
221
查看次数

标签 统计

asp.net ×1

c# ×1