Cannot implicitly convert type 'Chart.SeriesChartType' to 'System.Web.UI.DataVisualization.Charting.SeriesChartType'. An explicit conversion exists (are you missing a cast?)
RSS
Error Cannot implicitly convert type 'Chart.SeriesChartType' to 'System.Web.UI.DataVisualization.Charting.SeriesChartType'. An explicit conversion exists (are you missing a cast?)
Priya123gill
Member
51 Points
35 Posts
Cannot implicitly convert type 'Chart.SeriesChartType' to 'System.Web.UI.DataVisualization.Charti...
Feb 14, 2012 08:23 PM|LINK
I have chart control added to my aspx page, what I'm trying to do is there is a drop downlist where i can select Pyramid, Funnel, Doughnut, Radar any one of these and I will get that shaped chart. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Chart.aspx.cs" Inherits="Chart" %> <%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td> <div> <asp:Chart ID="Chart1" runat="server" DataSourceID="StudentEntityDataSource" BorderlineColor="Window" Palette="Chocolate"> <Series> <asp:Series Name="Series1" XValueMember="Name" YValueMembers="Marks"> </asp:Series> </Series> <ChartAreas> <asp:ChartArea Name="ChartArea1"> <Area3DStyle Rotation="15" Perspective="10" Enable3D="True" Inclination="15" IsRightAngleAxes="False" WallWidth="1" IsClustered="False" /> </asp:ChartArea> </ChartAreas> <BorderSkin BackColor="Highlight" /> </asp:Chart> </div> <div> <asp:Label ID="Label1" Text="Select Chart Type" runat="server" /> <asp:DropDownList ID="ddlCharType" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlCharType_SelectedIndexChanged"> </asp:DropDownList> </div> </td> <td valign="top"> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="StudentEntityDataSource" ForeColor="#333333" GridLines="None" CellPadding="4"> <AlternatingRowStyle BackColor="White" /> <Columns> <asp:CommandField ShowEditButton="True" ShowSelectButton="True" /> </Columns> <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" /> <RowStyle BackColor="#FFFBD6" ForeColor="#333333" /> <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" /> <SortedAscendingCellStyle BackColor="#FDF5AC" /> <SortedAscendingHeaderStyle BackColor="#4D0000" /> <SortedDescendingCellStyle BackColor="#FCF6C0" /> <SortedDescendingHeaderStyle BackColor="#820000" /> </asp:GridView> </td> </tr> </table> <asp:EntityDataSource ID="StudentEntityDataSource" runat="server" ConnectionString="name=StudentEntities" DefaultContainerName="StudentEntities" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="Students"> </asp:EntityDataSource> </ContentTemplate> </asp:UpdatePanel> </form> </body> </html> Code Behindusing System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.DataVisualization.Charting; public partial class Chart : System.Web.UI.Page { enum SeriesChartType { Pyramid, Funnel, Doughnut, Radar } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BindEnumToListControls(typeof(SeriesChartType), ddlCharType); } } public void BindEnumToListControls(Type enumType, ListControl listcontrol) { string[] names = Enum.GetNames(enumType); listcontrol.DataSource = names.Select((key, value) => new { key, value }).ToDictionary(x => x.key, x => x.value + 1); listcontrol.DataTextField = "key"; listcontrol.DataValueField = "value"; listcontrol.DataBind(); } protected void ddlCharType_SelectedIndexChanged(object sender, EventArgs e) { this.Chart1.Series["Series1"].ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), ddlCharType.SelectedItem.Text); } }
Getting error in this line
gmcgraffin
Participant
792 Points
137 Posts
Re: Cannot implicitly convert type 'Chart.SeriesChartType' to 'System.Web.UI.DataVisualization.Ch...
Feb 14, 2012 08:32 PM|LINK
Do you have another implementation of the ChartType enumeration within the System.Web.UI.DataVisualization.Charting namespace?
I have a feeling you may have 2 enumerations called ChartType in the same solution.
George
Please Mark the post as Answer if it helped
Priya123gill
Member
51 Points
35 Posts
Re: Cannot implicitly convert type 'Chart.SeriesChartType' to 'System.Web.UI.DataVisualization.Ch...
Feb 14, 2012 08:36 PM|LINK
Thanks for responding. No I don't have. Whatever code I have I have posted here including my .aspx page and code behind
Priya123gill
Member
51 Points
35 Posts
Re: Cannot implicitly convert type 'Chart.SeriesChartType' to 'System.Web.UI.DataVisualization.Ch...
Feb 14, 2012 08:54 PM|LINK
Sorry.. I had. Deleted one. Thanks for helping me.