In gridview as follows
Class Bthno Rate
MFA B101 50
EFA B102 70
ROC B103 80
CTF B104 90
TFC B105 95
I want to show the above gridview record in chart in asp.net using csharp.
for that i written the code below as follows
Code as follows
protected void Btn_Chart(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Class");
dt.Columns.Add("BatchNo");
dt.Columns.Add("Rate");
try
{
if (Ddlmonth.SelectedItem.Text.ToString().Trim() == "Select")
{
Label4.Text = "Select the month";
}
if (ddlyear.SelectedItem.Text.ToString().Trim() == "Select")
{
Label4.Text = "Select the year";
}
string month = Ddlmonth.SelectedValue.ToString();
sql = "select bthid,class,bthno from batch where month(examdate) = " + month + " and year(examdate) = " + ddlyear.SelectedValue.ToString() + " order by 1 asc";
dr = scon.ReadSql(sql);
while (dr.Read())
{
if (dr.HasRows)
{
sql = "select avg(case rate when 1 then 100 when 2 then 75 when 3 then 50 when 4 then 25 when 0 then 0 end) from studdet s, facfeedback f where f.studid =s.studid and f.answerid = s.answerid " +
"and f.bfid = '" + ddlfacid.SelectedValue.ToString() + "' and s.bthid = '" + dr[0].ToString().Trim() + "' order by 1 asc";
dr1 = scon.ReadSql(sql);
while (dr1.Read())
{
if (dr1[0].ToString() != "" && Convert.ToInt32(dr1[0].ToString()) != 0 && dr1[0].ToString() != "0")
{
dt.Rows.Add(dr[1].ToString().Trim(), dr[2].ToString(), dr1[0].ToString());
}
}
}
}
GridView3.DataSource = dt;
GridView3.DataBind();
GridView3.Visible = true;
dr.Close();
dr1.Close();
//Displaying the gridview records using chart
dr = scon.ReadSql(sql);
int[] LClass = new int[GridView3.Rows.Count];
dr1 = scon.ReadSql(sql);
int[] LRate = new int[GridView3.Rows.Count];
int i = 0;
while (dr.Read())
{
LClass[i] = int.Parse(dr[1].ToString());
while (dr1.Read())
{
LRate[i] = int.Parse(dr1[0].ToString());
Chart2.Series.Add(LClass[i].ToString());
i = i + 1;
}
dr.Close();
dr1.Close();
Chart2.Series["Series"].Points.DataBindXY(LClass, LRate);
Chart2.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
Chart2.ChartAreas["ChartArea1"].AxisX.Title = "Faculty BatchWise Report";
Chart2.ChartAreas["ChartArea1"].BackColor = Color.BurlyWood;
Chart2.ChartAreas["ChartArea1"].BackSecondaryColor = Color.Green;
Chart2.ChartAreas["ChartArea1"].BorderColor = Color.Blue;
Chart2.ChartAreas["ChartArea1"].BorderWidth = 2;
}
catch (Exception ex)
{
Label4.Text = "Error :" + ex.Message.ToString();
Label4.Visible = true;
return;
}
}
}
When i run shows error as follows
Index was outside the bound of array.
please help me what is the problem in my above code.
Regards,
Narasiman P.