图表控件内部数据列表
Chart Control Inside datalist
我有一个图表控件,我已将其放入数据列表项模板中,因为我想通过单击显示所有学生成绩单的图表。
当我将值绑定到图表时,我遇到了一个问题,但它总是在所有其他图表上显示最后一个学生分数,我希望不同的学生分数显示在不同的图表上。请帮帮我
protected void dlCategory_ItemDataBound(object sender, DataListItemEventArgs e)
{
DataSet dsStu = new DataSet();
string sqlStu = "SELECT distinct t.studentcode FROM tblcce9_studentgrades t join tblstudent st on t.studentcode=st.studentcode where examname='" + lblExamCode.Text + "' and st.classcode='" + lblClassCode.Text + "' and t.subpart='1' and st.recordstatus <>'D'";
dsStu = obj.openDataset(sqlStu, Session["SCHOOLCODE"].ToString());
if (dsStu.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < dsStu.Tables[0].Rows.Count; i++)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
string sqlchart = "select cl.classname,Concat(ga.forename,' ',ga.Surname) as fathername,s.studentcode,s.admissionnumber,s.studentname, sum(g.grade)" +
" as totalmarks,a.assessareaname,sub.subassessname,sub.maxmarks , e.examname from tblcce9_studentgrades g inner join" +
" tblstudent s on s.studentcode = g.studentcode inner join tblcce9_assessmentareas a on g.assessmentareacode =a.assessareacode" +
" inner join tblcce9_subassess sub on g.subassesscode=sub.id inner join tblcce9_examname e on g.examname=e.id inner" +
" join tblguardian ga on s.studentcode=ga.studentcode inner join tblclass cl on s.classcode = cl.classcode where" +
" sub.classcode='" + lblClassCode.Text + "' and s.studentcode='" + dsStu.Tables[0].Rows[i]["studentcode"] + "' and ga.relationshipcode='14' and s.recordstatus<>'D' group by assessareaname order by a.priority";
DataSet dschart = new DataSet();
dschart = obj.openDataset(sqlchart, Session["SCHOOLCODE"].ToString());
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Chart chrt = (Chart)e.Item.FindControl("Chart1");
if (dschart.Tables[0].Rows.Count > 0)
{
string[] x = new string[dschart.Tables[0].Rows.Count];
int[] y = new int[dschart.Tables[0].Rows.Count];
for (int k = 0; k < dschart.Tables[0].Rows.Count; k++)
{
x[k] = dschart.Tables[0].Rows[k]["assessareaname"].ToString();
y[k] = Convert.ToInt32(dschart.Tables[0].Rows[k]["totalmarks"].ToString());
}
chrt.Series[0].Points.DataBindXY(x, y);
chrt.Series[0].ChartType = SeriesChartType.Column;
//chrt.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
//chrt.Legends[0].Enabled = true;
}
}
}
}
}
}
它工作正常,只要您的 obj.openDataset()
返回正确的数据:
我有一个图表控件,我已将其放入数据列表项模板中,因为我想通过单击显示所有学生成绩单的图表。 当我将值绑定到图表时,我遇到了一个问题,但它总是在所有其他图表上显示最后一个学生分数,我希望不同的学生分数显示在不同的图表上。请帮帮我
protected void dlCategory_ItemDataBound(object sender, DataListItemEventArgs e)
{
DataSet dsStu = new DataSet();
string sqlStu = "SELECT distinct t.studentcode FROM tblcce9_studentgrades t join tblstudent st on t.studentcode=st.studentcode where examname='" + lblExamCode.Text + "' and st.classcode='" + lblClassCode.Text + "' and t.subpart='1' and st.recordstatus <>'D'";
dsStu = obj.openDataset(sqlStu, Session["SCHOOLCODE"].ToString());
if (dsStu.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < dsStu.Tables[0].Rows.Count; i++)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
string sqlchart = "select cl.classname,Concat(ga.forename,' ',ga.Surname) as fathername,s.studentcode,s.admissionnumber,s.studentname, sum(g.grade)" +
" as totalmarks,a.assessareaname,sub.subassessname,sub.maxmarks , e.examname from tblcce9_studentgrades g inner join" +
" tblstudent s on s.studentcode = g.studentcode inner join tblcce9_assessmentareas a on g.assessmentareacode =a.assessareacode" +
" inner join tblcce9_subassess sub on g.subassesscode=sub.id inner join tblcce9_examname e on g.examname=e.id inner" +
" join tblguardian ga on s.studentcode=ga.studentcode inner join tblclass cl on s.classcode = cl.classcode where" +
" sub.classcode='" + lblClassCode.Text + "' and s.studentcode='" + dsStu.Tables[0].Rows[i]["studentcode"] + "' and ga.relationshipcode='14' and s.recordstatus<>'D' group by assessareaname order by a.priority";
DataSet dschart = new DataSet();
dschart = obj.openDataset(sqlchart, Session["SCHOOLCODE"].ToString());
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Chart chrt = (Chart)e.Item.FindControl("Chart1");
if (dschart.Tables[0].Rows.Count > 0)
{
string[] x = new string[dschart.Tables[0].Rows.Count];
int[] y = new int[dschart.Tables[0].Rows.Count];
for (int k = 0; k < dschart.Tables[0].Rows.Count; k++)
{
x[k] = dschart.Tables[0].Rows[k]["assessareaname"].ToString();
y[k] = Convert.ToInt32(dschart.Tables[0].Rows[k]["totalmarks"].ToString());
}
chrt.Series[0].Points.DataBindXY(x, y);
chrt.Series[0].ChartType = SeriesChartType.Column;
//chrt.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
//chrt.Legends[0].Enabled = true;
}
}
}
}
}
}
它工作正常,只要您的 obj.openDataset()
返回正确的数据: