public void BindChart() { string query = string.Format("Select SubjectID,GradeID from dbo.tbl_StudentGrades where StudentID=1001 and TestID=1", "1001"); DataTable dt = GetData(query); string[] x = new string[dt.Rows.Count]; Decimal[] y = new Decimal[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { x[i] = dt.Rows[i][0].ToString(); y[i] = Convert.ToInt32(dt.Rows[i][1]); } LineChart1.Series.Add(new AjaxControlToolkit.LineChartSeries { Data = y }); LineChart1.CategoriesAxis = string.Join(",", x); LineChart1.ChartTitle = string.Format("Student Status Subjectwise", "StudentID"); if (x.Length > 3) { LineChart1.ChartWidth = (x.Length * 75).ToString(); } LineChart1.Visible = true; } private static DataTable GetData(string query) { DataTable dt = new DataTable(); string constr = "Data Source=xxxxx;Initial Catalog=sss;Persist Security Info=True;User ID=sasasa;Password=asasasas"; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(query)) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.CommandType = CommandType.Text; cmd.Connection = con; sda.SelectCommand = cmd; sda.Fill(dt); } } return dt; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)