如何防止Chart1.DataSource = null?

时间:2014-04-16 10:25:51

标签: c# asp.net sql-server

Chartid.DataSourceID = “SqlDataSourceID” 如果我再次给予 Chartid.DataSourceID =来自业务逻辑的数据表引用

如果抛出错误,说不能同时使用两个数据源......,请删除一个。

在删除数据源时,同时调用chartid.databind(); 在点击断点时,我意识到我的datasource = null在回发条件之后发生。

请指导我消除此错误。

这里是设计:

<asp:Chart ID="Chart1" runat="server" DataSourceID="SqlDataSource2" ImageLocation="~/TempImages/ChartPic_#SEQ(300,3)" ImageStorageMode="UseImageLocation"> <Series> 
<asp:Series Name="Series1" ChartType="Pie" ChartArea="ChartArea1" XValueMember="Target_Category" YValueMembers="Orders" Color="Green" XValueType="String" YValueType="Double" >
</asp:Series> 
</Series> 
<ChartAreas> 
<asp:ChartArea Name="ChartArea1" > 
<Area3DStyle Enable3D="True" Rotation="90" Inclination="0"/> </asp:ChartArea> </ChartAreas> 
</asp:Chart>

这是代码:

Chart1.Series["Series1"].XValueMember = "Target_Category"; 
Chart1.Series["Series1"].YValueMembers = "Orders"; 
Chart1.Series["Series1"]["PieLabelStyle"] = "outside"; 
Chart1.Series["Series1"]["PointWidth"] = "0.1"; 
int User_Id = User_ID; 
SessionParameter spuid = new SessionParameter();
spuid.Name = "User_Id"; 
spuid.Type = TypeCode.Int32; 
spuid.SessionField =Convert.ToInt32( Session["User_Id"]).ToString(); 
Chart1.DataSourceID = "SqlDataSource1"; 
Chart1.DataBind() ; Chart1.Visible = true;

0 个答案:

没有答案