变量后面的代码没有在前端ASPX页面中解析

时间:2013-08-21 14:16:31

标签: c# .net

我们的一个前端页面背后有一个代码,需要访问一个字符串来解析一个asp对象。但是,在aspx页面上调用字符串变量时,会出现以下错误:

Parser Error 
Description: An error occurred during the parsing of a resource required to service this    request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: Cannot create an object of type 'System.Decimal[]' from its string representation '<%=strMonths%>' for the 'Data' property.

Source Error:

Line 47:                     <asp:BarChart ID="BarChart2" runat="server" ChartHeight="300" ChartWidth="425" ChartType="Column" ChartTitle="Month - Summary" CategoriesAxis="Jan.,Fed.,Mar.,Apr.,May,June,July,Aug.,Sept.,Oct.,Nov,Dec" ChartTitleColor="#000000" CategoryAxisLineColor="#CCCCCC" ValueAxisLineColor="#CCCCCC" BaseLineColor="#CCCCCC"  BorderStyle="None">
Line 48:                         <Series>
Line 49:                             <asp:BarChartSeries Name="Unique Visits" BarColor="#FFCC00" Data="<%=strMonths%>" />
Line 50:                             <asp:BarChartSeries Name="Average Session" BarColor="#CCCCCC" Data="49,77,95,68,70,79,110,189,255,95,107,14" />
Line 51:                         </Series>

背后的代码:

public string strMonths;

public void btnSubmit_Click(object sender, EventArgs e)
{
    string strBU = BU_Selector.SelectedValue;
    string strSQL = “--- My Query Here ---”
    string connString = ConfigurationManager.ConnectionStrings["Analytics"].ConnectionString;
    DataSet dataset = new DataSet();

    using (SqlConnection conn = new SqlConnection(connString))
    {
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand(strSQL, conn);
        conn.Open();
        adapter.Fill(dataset);
    }

    Int32 i = 0;
    DataTable dt = dataset.Tables[0];
    while (i < dt.Rows.Count)
    {
        strMonths += dt.Rows[i][0].ToString() + "," + dt.Rows[i][1].ToString() + "," + dt.Rows[i][2].ToString() + "," + dt.Rows[i][3].ToString() + "," + dt.Rows[i][4].ToString() + "," + dt.Rows[i][5].ToString() + "," + dt.Rows[i][6].ToString() + "," + dt.Rows[i][7].ToString() + "," + dt.Rows[i][8].ToString() + "," + dt.Rows[i][9].ToString() + "," + dt.Rows[i][10].ToString() + "," + dt.Rows[i][11].ToString();
        i++;
    }
    resultstable.Visible = true;
}

0 个答案:

没有答案