Exemplo n.º 1
0
        protected void rptResult_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
            {
                return;
            }
            M_Question rowv = (M_Question)e.Item.DataItem;

            if (rowv.TypeID >= 3)
            {
                ((HtmlGenericControl)e.Item.FindControl("divTable")).Style["display"] = "none";
                (e.Item.FindControl("ltlTitle") as Literal).Text = rowv.QuestionTitle;
                return;
            }
            GridView      gview   = e.Item.FindControl("gviewOption") as GridView;
            string        options = rowv.QuestionContent;//内容
            List <string> lstopts = new List <string>();

            for (int i = 0; i < options.Split('|').Length; i++)
            {
                lstopts.Add(options.Split('|')[i].Split(':')[0]);
            }

            int    sum    = 0;
            string ratios = "";
            string names  = "";

            gview.RowDataBound += delegate(object s, GridViewRowEventArgs ex)
            {
                int    total  = 0;
                string rate   = "";
                int    papers = B_Survey.GetUsersCnt(rowv.SurveyID);
                if (ex.Row.RowType == DataControlRowType.DataRow)
                {
                    total = B_Survey.GetAnsOptionCount(rowv.QuestionID, ex.Row.DataItem.ToString());
                    (ex.Row.FindControl("ltlTotal") as Literal).Text = total.ToString();
                    sum += total;
                    if (papers == 0)
                    {
                        rate = "未填写";
                    }
                    else
                    {
                        rate = ((float)total / papers).ToString("P");
                    }
                    (ex.Row.FindControl("ltlRate") as Literal).Text = rate;
                    names  += CutContent(ex.Row.DataItem.ToString(), 4) + ",";
                    ratios += total + ",";
                }
                if (ex.Row.RowType == DataControlRowType.Footer)
                {
                    (ex.Row.FindControl("ltlSum") as Literal).Text = papers.ToString();
                }
            };
            gview.DataSource = lstopts;
            gview.DataBind();
        }