TAGS :Viewed: 8 - Published at: a few seconds ago

[ MS Chart Parsing ChartType from a string ]

I want to parse the ChartType from a dropdown list but I couldnt parse the value, Is there anyway to parse it ?

using System.Web.UI.DataVisualization.Charting;
...
...
Chart2.Series[0].ChartType = Enum.Parse(typeof(SeriesChartType.Area), DropDownList1.Text);

Thx in advance!

Answer 1


You probably don't want to specify .Area:

Chart2.Series[0].ChartType = Enum.Parse(typeof(SeriesChartType), DropDownList1.Text);

Answer 2


You could populate the DropDownList1 with the enumeration.

The string representation of the enumeration name would be displayed as the text in DropDownList1.

DropDownList1.Items.AddRange = Enum.GetValues(typeof(SeriesChartType));

Then you can access the items of the list.

Chart2.Series[0].ChartType = (SeriesChartType)DropDownList1.SelectedItem;

Answer 3


your MS control has a Type

i.e Chart.Series[0].TypeName = DropDownList.Selectvalue.text

only work on the Control its self if you refrence the using

System.Web.UI.DataVisualization.Charting and create an object from that it wont work