读书人

优化asp.net代码解决方案

发布时间: 2012-04-28 11:49:53 作者: rapoo

优化asp.net代码

C# code
    /// <summary>    /// 绑定产品目录列表    /// </summary>    /// <param name="cid">公司ID</param>    protected void BindBigProductCataLog(string cid)    {        Catagary ca = new Catagary();        BllGlodMemberProductCatagorySort bllcatagory = new BllGlodMemberProductCatagorySort();        ArrayList al = ca.GetOfferCatalogIDSort(cid);        ArrayList al_temp = null;        ArrayList al2 = bllcatagory.GetCatalogList(cid);        if (al != null && al2 != null)        {            if (al.Count == al2.Count)            {                al = al2;            }        }        DataTable dt = ca.GetAllProductCatalogChildSort(cid);         DataTable dt2 = bllcatagory.GetChildCatalogList(cid);        rptCatalogOne.DataSource = al;        rptCatalogOne.DataBind();        foreach (RepeaterItem rpone in rptCatalogOne.Items)        {            int i = rpone.ItemIndex;            int cateGoryoneId;            if (int.TryParse(al[i].ToString(), out cateGoryoneId))            {                 DataTable listTwo =null;                if (dt != null)                {                    listTwo = ca.GetChildCatalogListByParentIDSort(cateGoryoneId, dt);                }                DataTable listThree = null;                if (dt2 != null)                {                    listThree = ca.GetChildCatalogListByParentIDSort(cateGoryoneId, dt2);                }                DataTable list_temp = null;                if (listThree != null && listTwo != null)                {                    if (listTwo.Rows.Count == listThree.Rows.Count)                    {                        list_temp = listThree;                    }                    else                    {                        list_temp = listTwo;                    }                }                else                {                    list_temp = listTwo;                }                Repeater rptCatalogTwo = (Repeater)rpone.FindControl("rptCatalogTwo");                rptCatalogTwo.DataSource = listTwo;                rptCatalogTwo.DataBind();            }        }    }


[解决办法]
这个方法调用多 吗

如果多
就把 BllGlodMemberProductCatagorySort bllcatagory = new BllGlodMemberProductCatagorySort();
放全局吧
[解决办法]
那datatable放using 使用完就释放

你这里datatable的使用频率太高了

读书人网 >asp.net

热点推荐