Example #1
0
        protected void rptReuslt_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
            {
                return;
            }
            Repeater   rep  = e.Item.FindControl("rptOption") as Repeater;
            Label      lbl  = e.Item.FindControl("lblTip") as Label;
            M_Question rowv = (M_Question)e.Item.DataItem;

            if (rowv.TypeID > 2)
            {
                rep.Visible = false;
                lbl.Visible = true;
                return;
            }
            lbl.Visible = false;
            string options = rowv.QuestionContent;

            if (options.Length <= 0)
            {
                options = " 暂时没有添加选项内容。。。";
            }
            List <string> lstopts = new List <string>();

            lstopts.AddRange(options.Split('|'));
            int qid = rowv.QuestionID;
            int sid = rowv.SurveyID;

            rep.ItemDataBound += delegate(object obj, RepeaterItemEventArgs ex)
            {
                if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
                {
                    return;
                }
                if (ex.Item.DataItem != null)
                {
                    string item     = ex.Item.DataItem.ToString().Split(':')[0];
                    int    count    = surBll.SelectNum(sid, qid, item);
                    int    papers   = surBll.GetQuCount(qid);
                    string strPcent = "";
                    if (papers == 0)
                    {
                        strPcent = "未填写";
                    }
                    else
                    {
                        strPcent = ((float)count / papers).ToString("P");
                    }
                    Image img = ex.Item.FindControl("imgBar") as Image;
                    if (count == 0)
                    {
                        img.Style["Width"] = "0.2%";
                        (ex.Item.FindControl("lblPercent") as Label).Text = "0票/" + strPcent + "<span style='color:green;'>(0分)</span>";
                    }
                    else
                    {
                        img.Style["width"] = strPcent;
                        (ex.Item.FindControl("lblPercent") as Label).Text = count + "票/" + strPcent + "<span style='color:green;'>(分)</span>";//" + (count * score) + "
                    }
                }
            };
            rep.DataSource = lstopts;
            rep.DataBind();
        }