Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I am working on dotnetCharting Drildown and wile choosing year from the dropdown the selected year details should come on my chart.

What I have tried:

C#
<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Drawing2D;
using dotnetCHARTING;
using System.Configuration;
using System.Data.SqlClient;

namespace dotnetdrilldown03
{
    public partial class DrillDropdown : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Chart.DefaultSeries.ConnectionString = ConfigurationManager.ConnectionStrings["sqlconnection"].ConnectionString;
            if (!IsPostBack)
            {
                Bindddl();
            }
                Chart.YAxis.Label.Text = "No of Students";
                Chart.Title = "Progress Report";
                Chart.XAxis.Label.Text = "Years";
                Chart.Width = 750;
                Chart.Height = 550;
                Chart.Debug = true;
                Chart.DateGrouping = TimeInterval.Years;
                Chart.DrillDownChain = "Years,Quarters,Months,Full";
                Chart.DefaultSeries.DefaultElement.ToolTip = "%yvalue";
                Chart.Series.Name = "Bonus points";
                Chart.Series.StartDate = new System.DateTime(2014, 1, 1, 0, 0, 0);
                Chart.Series.EndDate = new System.DateTime(2017, 12, 31, 23, 59, 59);
                Chart.Series.SqlStatement = @"SELECT Duration,Total FROM Report WHERE Duration >= #STARTDATE#  ";

                Chart.SeriesCollection.Add();
            
        }

        protected void Bindddl()
        {
            Ddldrill.Items.Add("2014");
            Ddldrill.Items.Add("2015");
            Ddldrill.Items.Add("2016");
            Ddldrill.Items.Add("2017");
            if (Request.QueryString["limitMode"] != null)
                Ddldrill.SelectedIndex = (int)Enum.Parse(typeof(dotnetCHARTING.LimitMode), Request.QueryString["limitMode"], true);
            Chart.Series.LimitMode = (dotnetCHARTING.LimitMode)Enum.Parse(typeof(dotnetCHARTING.LimitMode), Ddldrill.SelectedItem.Value, true);
            Ddldrill.DataBind();
            Ddldrill.Items.Insert(0, new ListItem("--Select--"));

            if (Ddldrill.SelectedItem.Value = "")
            { 
            
            }
        }

        protected void Ddldrill_SelectedIndexChanged(object sender, EventArgs e)
        {
            Bindddl();
        }
        dotnetCHARTING.SeriesCollection Calculate()
        {
            dotnetCHARTING.SeriesCollection SC = new dotnetCHARTING.SeriesCollection();
            Random myR = new Random(1);
            for (int a = 0; a < 4; a++)
            {
                dotnetCHARTING.Series s = new dotnetCHARTING.Series();
                s.Name = "Series " + a.ToString();
                for (int b = 0; b < 1; b++)
                {
                    Element e = new Element();
                    e.Name = "Element " + b.ToString();
                    e.YValue = myR.Next(20);
                    s.Elements.Add(e);
                }

                SC.Add(s);
            }
            SC[0].Element.Color = Color.FromArgb(49, 255, 49);
            SC[0].Elements[0].Name = "English";
            SC[0].LegendEntry.Value = "13";
            SC[0].LegendEntry.Name = "Between 10-15";
            return SC;
        }
    }
}
Posted
Updated 5-Mar-17 20:31pm

1 solution

ASP.NET has both code in the page and a code-behind. You are missing an important part to help resolve your issue - the .ASPX page. You question is not describing the symptoms - eg: my car won't start. What happens when you turn the key? I hear a noise? what noise? etc... Without details, it is anyone's guess!

Now, I am a MVC dev, not a Asp.Net WebPage dev, so it took me a few moments to adjust. So, here is my stab-in-the-dark guess: I think that you are missing a property on your DropDownList:
AutoPostBack="True"
causing the DropDownList selected event in the code-behind to not fire.

To demonstrate the DropDownList peforming as I think you want it to, here is a working example:

1. Page:
ASP.NET
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

        <div class="col-md-4">
            <h2>DropDown Test</h2>
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        </div>

</asp:Content>
2. Code-behind
C#
using System;
using System.Collections.Generic;
using System.Web.UI;

namespace WebApplication1
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitData();
            }

        }

        public List<string> Options { get; set; }
        private void InitData()
        {
            Options = new List<string> { "AAA", "BBB", "CCC" };
            foreach (var item in Options)
            {
                DropDownList1.Items.Add(item);
            }
            DropDownList1.SelectedIndex = 0;
            SetLabel();

        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetLabel();
        }

        private void SetLabel()
        {
            Label1.Text = DropDownList1.SelectedItem.Text;
        }
    }
}
 
Share this answer
 
Comments
Member 12605293 6-Mar-17 2:39am    
Hi Graeme
Thanks for the advice,

Here is my aspx:








<ASP:Label id="Label1" runat="server" Width="100px" Text="Choose Year">

<ASP:DropDownList id="Ddldrill" runat="server" Width="100px" AutoPostBack="True" OnSelectedIndexChanged="Ddldrill_SelectedIndexChanged">



<dotnet:Chart ID="Chart" runat="server" />


Issue is ,Initially the chart shows all the years in bar diagram,and While selecting the value in ddl it is not showing the selected year
Member 12605293 6-Mar-17 2:42am    
Also the value in ddl is repeating twice in postback
Graeme_Grant 6-Mar-17 3:04am    
start a new project, use my code, and see how it works.

If you are still having problems, set breakpoints and step through your code.
Graeme_Grant 6-Mar-17 3:07am    
Also, post this information in your question where others can see it. Move information in the question, as mentioned in the intro of my solution, is needed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900