现在的位置: 首页 > 综合 > 正文

gridview repeater 根据(分类id列出分类名)

2012年04月05日 ⁄ 综合 ⁄ 共 814字 ⁄ 字号 评论关闭

   gridview中

在cs里

 protected void GridViewData_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int ClassId = (int)DataBinder.Eval(e.Row.DataItem, "ClassId");
            Cn1yw.Bll.Gq_Class bll = new Cn1yw.Bll.Gq_Class(); 
            string title = bll.GetModelByCache(ClassId, 1);//传classId修改你自己的
            if (title != null)
            {
                e.Row.Cells[1].Text = title; // 列从0开始cells[1]表示第二列 
            }
            else
            {
                e.Row.Cells[1].Text = "未知类型";
            }
        }

repeater 中

在aspx页面里

<%# CompanyName(Convert.ToInt32(Eval("Classid"))) %>

在cs里

    public string CompanyName(int classid)
    {
     Cn1yw.Bll.Gq_Class bll = new Cn1yw.Bll.Gq_Class();//修改你自己的
     string companytitle = bll.GetModelByCache(classid, 1); //修改你自己的
     return companytitle;
    }

 

抱歉!评论已关闭.