0
votes

I have a drill down chart that i built in ASP.net using C#, in Microsoft Visual Studio 12 and an ACCESS database.

These are my connection string and sql query statement

string myConnectionString = "Path"; 
string mySelectQuery = "mysqlstatement";

Path and mysqlstatement are just examples because I dont get much space to write here on stackoverflow text box. Nevertheless

using (OleDbConnection myConnection = new OleDbConnection(myConnectionString))
{
    OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);
    myConnection.Open();
    OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

    Chart1.DataBindTable(myReader, "Region Name");
    myConnection.Close();
    Series Series1 = new Series();
    Chart1.Series.Add(Series1);
    Series1.XValueMember = "Region Name";
    Series1.YValueMembers = "TotalSales";`

This is how I bind data to my chart. I choose a value say 2011 from my drop down list and it load up the appropriate data into Chart1. BUT if I choose 2010 from my drop down list, how can I get a message to appear on screen or label box that says there is no data for this year.

At the moment it just displays a blank chart1 with heading. So i am looking for a condition that checks the series if it contains data or not, if it doesnt that prints that error and breaks or stops.

Thanks in advance

1

1 Answers

0
votes

Assuming you have just one series you could try something like this:

protected void Chart1_DataBound(object sender, EventArgs e)
{
    if (Chart1.Series[0].Points.Count == 0)
        Label1.Text = "No DATA";
}