2012-11-23 133 views
1

c#刚刚有一个按钮,单击时这样做有一个firePie.aspx页面,传递参数

protected void Button1_Click(object sender, EventArgs e) 
    { 
     string cadenaValor, valores; 
     cadenaValor = "Audi(28%)','BMW(29%)','Mercedes(22%)" ; 
     valores = "28,29,22"; 
     Response.Redirect("pieChart.aspx?values="+cadenaValor+"&valores="+valores); 
    } 

的参数是逗号分隔值的字符串,我想这个值传递给piechart.aspx所以在javascript捕捉功能的参数和打印饼图中,pieChart.aspx代码:

<body> 
<canvas id="cvs" width="450" height="300">[No canvas support]</canvas>   
<form id="frm" method="get" > 
     <script type ="text/javascript" > 
      var pie1 = new RGraph.Pie('cvs', ['<%=this.Request.QueryString["valores"]%>']); 
     pie1.Set('chart.radius', 100); 
     pie1.Set('chart.tooltips', ['<%=this.Request.QueryString["values"]%>']); 
     pie1.Set('chart.labels', ['<%=this.Request.QueryString["values"]%>']); 
     pie1.Set('chart.strokestyle', 'white'); 
     pie1.Set('chart.linewidth', 5); 
     pie1.Set('chart.shadow', true); 
     pie1.Set('chart.shadow.blur', 10); 
     pie1.Set('chart.shadow.offsetx', 0); 
     pie1.Set('chart.shadow.offsety', 0); 
     pie1.Set('chart.shadow.color', '#000'); 
     pie1.Set('chart.text.color', '#999'); 

     var explode = 20; 

     function myExplode (obj) 
     { 
      window.__pie__ = pie1; 

      for (var i=0; i<obj.data.length; ++i) { 
       setTimeout('window.__pie__.Explode('+i+',10)', i * 50); 
      } 
     } 

     if (RGraph.isOld()) { 
      pie1.Draw(); 

     } else if (navigator.userAgent.toLowerCase().indexOf('firefox') >= 0) { 
      RGraph.Effects.Pie.RoundRobin(pie1); 

     } else { 
      /** 
      * The RoundRobin callback initiates the exploding 
      */ 

      RGraph.Effects.Pie.RoundRobin(pie1, null, myExplode); 
      RGraph.Effects.Pie.Implode(pie1); 
     } 
    </script>   

</form> 
</body> 

QueryString["valores"]不工作,如果我写的origi nal字符串,我的意思是,28,29,22行var pie1 = new RGraph.Pie('cvs'...它的工作原理,我认为由于任何原因javascript不能识别这个值,但QueryString["values"]被正确捕获。你能帮我吗?

+1

它应该被标记为C#,ASPX .. –

+0

增加了c#asp.net标签 – psema4

回答

0

你是否能够从查询字符串中捕获值?

我有一个js函数从查询字符串中获取价值:

function getQueryVariable(variable) { 
    var query = window.location.search.substring(1); 
    var vars = query.split("&"); 
    for (var i=0;i<vars.length;i++) { 
     var pair = vars[i].split("="); 
     if(pair[0] == variable) { 
      return pair[1]; 
     } 
    } 
    return(false); 
} 

,你可以调用函数作为getQueryVariable("valores")你的情况。

看看这有助于

0

尝试在pieChart.aspx

<body> 
<canvas id="cvs" width="450" height="300">[No canvas support]</canvas>   
<form id="frm" method="get" > 
     <script type ="text/javascript" > 
      var pie1 = new RGraph.Pie('cvs', [<%=this.Request.QueryString["valores"]%>]); 
    pie1.Set('chart.radius', 100); 
    pie1.Set('chart.tooltips', [<%=this.Request.QueryString["values"]%>]); 
    pie1.Set('chart.labels', [<%=this.Request.QueryString["values"]%>]); 
... 

除去额外的报价和代码添加引号后面

protected void Button1_Click(object sender, EventArgs e) 
    { 
     string cadenaValor, valores; 
     cadenaValor = "'Audi(28%)','BMW(29%)','Mercedes(22%)'" ; //added here 
     valores = "28,29,22"; //No quotes here 
     Response.Redirect("pieChart.aspx?values="+cadenaValor+"&valores="+valores); 
    }