2010-01-26 41 views
1

我想从下拉列表中解析ChartType,但我无法解析值, 有没有办法解析它?MS Chart从字符串解析ChartType

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

Thx提前!

+0

的typeof(SeriesChartType)也不管用! – Kubi 2010-01-26 16:43:13

+0

忽视案件失败吗? – 2010-01-26 16:46:12

+0

nope它不适用于忽略情况 – Kubi 2010-01-26 16:48:12

回答

0

你可以填充DropDownList1与枚举。

枚举名称的字符串表示形式将显示为DropDownList1中的文本。

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

然后你就可以访问列表中的项目。

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

1

你可能不希望指定.Area:

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

你的MS控制有一个类型

即Chart.Series [0] = .TypeName DropDownList.Selectvalue.text

只对防治工作的自我,如果你refrence的使用

System.Web.UI.DataVisualization.Charting并创建一个对象从它不会工作