1、自定义控键画图:DrawControl.ascx
public class DrawControl : System.Web.UI.UserControl
{
Hashtable colHashtable;
/// <summary>
/// 用来设置柱状图的数据值以及对应的名称
/// </summary>
public Hashtable ColHashtable
{
set { colHashtable = value; }
}
private void Page_Load(object sender, System.EventArgs e)
{
IDictionaryEnumerator myHt = colHashtable.GetEnumerator();
.................//根据Hashtable的数据
.................
//一块画布,这里宽、高分别是arrValues.Length*50和topValue
Bitmap objBitMap = new Bitmap(arrValues.Length*100, topValue); 
Graphics objGraphics; 
objGraphics = Graphics.FromImage(objBitMap); 
//画柱状图
.................
//将objGraphics对象以指定的图形格式保存到指定的Stream对象,并输出到客户端
objBitMap.Save(Response.OutputStream, ImageFormat.Gif); 
}2、根据给定的条件,获得数据付给Hashtable,显示在Report.aspx页面上(数据操作都在Report.cs里实现)
   通过Image.ImageUrl = "DrawPanel.aspx";来实现
//////////////////////////////////////////////////////////////////
数据:DrawClass.DataHT = 查询所得数据形成的Hashtable; 3、DrawPanel.aspx放置自定义控键
    public class DrawPanel : System.Web.UI.Page
{ protected 自定义控键 自定义控键对象;
private void Page_Load(object sender, System.EventArgs e)
{
Hashtable dataHt = new Hashtable();
///////////////////////////////////////////////////////////////
dataHt = DrawClass.DataHT;
自定义控键对象.ColHashtable = dataHt;
}
4、一个类,主要目的,传递参数
public class DrawClass
{
public static Hashtable DataHT;
public DrawLineClass()
{
}
}
问题:感觉4这样传递参数很别扭,大家有什么其它好的方法么?

解决方案 »

  1.   

    看不明白你的意思,我感觉至少这里多了一些代码,白白new 了一个hashtable
    Hashtable dataHt = new Hashtable(); //这里已经new 了一个
    dataHt = DrawClass.DataHT; //引用又指向这个呢,上面那个对像就没有引用指向它了//改成这样
    Hashtable dataHt = DrawClass.DataHT;
    如果你要对hashtable进行操作后在传出来,也可以写成一个类,必竟通用嘛
    public class DrawClass
    {
    public static Hashtable DataHT;
    public DrawLineClass()
    {
    }
             static DrawLineClass()
             {
              //对DataHT进行初始化
             } 
    }
      

  2.   

    回复人: rickjelly2004(rick & jelly) ( ) 信誉:100  2005-04-08 16:25:00  得分: 0  
     
     
       用户控件一般是用属性来传参数啊 回复人: zyug(LovlyPuppy) ( ) 信誉:100  2005-04-08 16:26:00  得分: 0  
    ========================================================================================== 
    因为要把自定义控键放置在DrawPanel.aspx页面上,而显示Report.aspx页面上(数据操作都在Report.cs里实现,所以要在这里构造Hashtable数据,并且传递给在DrawPanel.aspx页面的自定义控键的属性)通过Image.ImageUrl = "DrawPanel.aspx";来实现感觉现在public class DrawClass只是利用静态属性来传递参数了,也没有生成对象,这种用法感觉别扭,能否给指点一下
      

  3.   

    在ASP.Net中,如果是Static,它的效果就相当于 Application
    那你还不如放到 Application 中