2006年9月6日

/*Title:给一个用户控件加自定义的事件
 *Author: Alvin
 *Date: Sep 6,2006
 *Description: 给一个用户控件加自定义的事件 并回传一个参数
 *Environment: WinXP sp2,Vs2005 pro,.netFramework 2.0
 *KeyWord: 给一个用户控件加自定义的事件 并回传一个参数 UserControl
 */
Step 1
 
新建一个类:
CustomerEventArgs.cs
 
public class CustomerEventArgs : EventArgs
{
  private int m_SelectId;
 
  public int SelectId
  {
    get { return m_SelectId; }
    set { m_SelectId = value; }
  }
  public CustomerEventArgs(int p_SelectId)
  {
    this.SelectId = p_SelectId;
  }
}
 
Step 2
新建一个用户控件 Add new Web User Control
并在控件上放两个 Button  如下
WebUserControl.ascx
 
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:Button ID="Button2" runat="server" Text="Button" />
 
Step 3
打开WebUserControl.ascx.cs
3.1
 定义一个代理类型
 public event CustomerEventHandler customerEvent;
3.2
 定义事件
 public event CustomerEventHandler customerEvent;
3.3
定义方法 OncustomerEvent来处理事件
  public virtual void OncustomerEvent(CustomerEventArgs e)
  {
    if (customerEvent != null)
    {
      customerEvent(this, e);
    }
  }
 
Step 4
给两个button 加上事件
 
WebUserControl.ascx
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
 
WebUserControl.ascx.cs
  protected void Button1_Click(object sender, EventArgs e)
  {
    OncustomerEvent(new CustomerEventArgs(1));
  }
  protected void Button2_Click(object sender, EventArgs e)
  {
    OncustomerEvent(new CustomerEventArgs(2));
  }
Step 5
 打开 default.aspx 引用并以上控件 并写好事件
 
default.aspx
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<%@ Register Src="WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %>
 
<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <uc1:WebUserControl ID="WebUserControl1" runat="server" OncustomerEvent="CustomerEvent" />
   
    </div>
    </form>
</body>
</html>
 
default.aspx.cs
 
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
  protected void CustomerEvent(object o, CustomerEventArgs e)
  {
    Response.Write(e.SelectId.ToString());
 
  }
}

posted @ 2006-09-06 23:39 Alvin Ye 叶冬开 阅读(536) | 评论 (0)编辑


2006年8月27日

/*Title: ZedGraph 在 web 中的应用
 *Author: AlvinYe
 *Date: Aug 27,2006
 *Description: ZedGraph 在 web 中的应用
 *Environment: WinXP sp2,Vs2005 pro,.netFramework 2.0
 *KeyWord: ZedGraph 在 web 中的应用 theme
 */

1.新建一个站点
2.引用ZedGraph.Web.dll 和 ZedGraph.dll 
www.ZedGraph.org 可以下载到
 
3修改default2.aspx 改为以下内容
<%@ Page Language="C#" CodeFile="Default2.aspx.cs" Inherits="Default2" Theme="" %>
<%@ Register TagPrefix="zgw" Namespace="ZedGraph.Web" Assembly="ZedGraph.Web" %>
<ZGW:ZEDGRAPHWEB id="ZedGraphWeb1" runat="server" width="500" Height="375" RenderMode="RawImage" />
 
注意其中的Theme="" 如果你在web.config 中已经设置好theme的话默认所有页都会先加载theme
因为我们这里只要生成图片,如果加载Theme 就会显示错误,看到乱码.
 
4.修改default.aspx.cs 改为
using System;
using System.Drawing;
 
using ZedGraph;
using ZedGraph.Web;
 

public partial class Default2 : System.Web.UI.Page
{
  protected void Page_Load(object sender, System.EventArgs e)
  {
  }
 
  #region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
  }
 
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {
    this.ZedGraphWeb1.RenderGraph += new ZedGraph.Web.ZedGraphWebControlEventHandler(this.OnRenderGraph);
 
  }
  #endregion
 
  /// <summary>
  /// This method is where you generate your graph.
  /// </summary>
  /// <param name="masterPane">You are provided with a MasterPane instance that
  /// contains one GraphPane by default (accessible via masterPane[0]).</param>
  /// <param name="g">A graphics instance so you can easily make the call to AxisChange()</param>
  private void OnRenderGraph(System.Drawing.Graphics g, ZedGraph.MasterPane masterPane)
  {
    // Get the GraphPane so we can work with it
    GraphPane myPane = masterPane[0];
 
    myPane.Title.Text = "学期成绩表";
    myPane.XAxis.Title.Text = "学期";
    myPane.YAxis.Title.Text = "成绩";
 
    PointPairList list = new PointPairList();
    PointPairList list2 = new PointPairList();
    PointPairList list3 = new PointPairList();
 
    DataTable dt = BuildDt();
 
    for (int i = 0; i < dt.Rows.Count; i++)
    {
      if (dt.Rows[i]["Id"].ToString() == "1")
      {
        list.Add(Convert.ToDouble(dt.Rows[i]["XueQi"]), Convert.ToDouble(dt.Rows[i]["FenShu"]), "Alvin");
      }
      else if (dt.Rows[i]["Id"].ToString() == "2")
      {
        list2.Add(Convert.ToDouble(dt.Rows[i]["XueQi"]), Convert.ToDouble(dt.Rows[i]["FenShu"]), "Robin");
      }
      else
      {
        list3.Add(Convert.ToDouble(dt.Rows[i]["XueQi"]), Convert.ToDouble(dt.Rows[i]["FenShu"]), "Jim");
      }
    }
 
    LineItem MyLine = myPane.AddCurve("Alvin", list, Color.Red, SymbolType.HDash);
    LineItem MyLine2 = myPane.AddCurve("Robin", list2, Color.Green);
    LineItem MyLine3 = myPane.AddCurve("Jim", list3, Color.Blue);
    masterPane.AxisChange(g);
  }
 
  private DataTable BuildDt()
  {
    DataTable dt = new DataTable("Students");
    dt.Columns.Add("Id");
    dt.Columns.Add("Name");
    dt.Columns.Add("XueQi");
    dt.Columns.Add("FenShu");
 
    dt.Rows.Add(1, "Alvin", "1", 100);
    dt.Rows.Add(1, "Alvin", "2", 90);
    dt.Rows.Add(1, "Alvin", "3", 80);
    dt.Rows.Add(1, "Alvin", "4", 120);
    dt.Rows.Add(2, "Robin", "1", 120);
    dt.Rows.Add(2, "Robin", "2", 100);
    dt.Rows.Add(2, "Robin", "3", 90);
    dt.Rows.Add(2, "Robin", "4", 110);
    dt.Rows.Add(3, "Jim", "1", 80);
    dt.Rows.Add(3, "Jim", "2", 90);
    dt.Rows.Add(3, "Jim", "3", 130);
    dt.Rows.Add(3, "Jim", "4", 135);
 
    return dt;
 
  }
}
 
运行结果如下






 

posted @ 2006-08-27 13:16 Alvin Ye 叶冬开 阅读(1714) | 评论 (8)编辑


2006年5月31日

JavaScript 弹出一个可移动的框
文章来源:http://blog.csdn.net/Open2ye/archive/2006/05/31/765422.aspx

posted @ 2006-05-31 20:01 Alvin Ye 叶冬开 阅读(75) | 评论 (0)编辑


2006年5月19日

C# 为一个方法添加事件的方法 Event delegate
文章来源:http://blog.csdn.net/Open2ye/archive/2006/05/19/745041.aspx

posted @ 2006-05-19 17:06 Alvin Ye 叶冬开 阅读(348) | 评论 (0)编辑


2006年5月18日

解决IE sp1 网页上有 Flash 要先激活才能点击的问题
文章来源:http://blog.csdn.net/Open2ye/archive/2006/05/18/743863.aspx

posted @ 2006-05-18 19:55 Alvin Ye 叶冬开 阅读(103) | 评论 (0)编辑


2006年5月14日

把Web上传到 FreeBSD 系统上要注意
文章来源:http://blog.csdn.net/Open2ye/archive/2006/05/14/728113.aspx

posted @ 2006-05-14 22:17 Alvin Ye 叶冬开 阅读(34) | 评论 (0)编辑


2006年5月13日

用Excel 做 员工轮班表 lookup
文章来源:http://blog.csdn.net/Open2ye/archive/2006/05/13/727259.aspx

posted @ 2006-05-13 22:36 Alvin Ye 叶冬开 阅读(588) | 评论 (0)编辑


2006年5月10日

在Php4上的ajax Xajax
文章来源:http://blog.csdn.net/Open2ye/archive/2006/05/10/721677.aspx

posted @ 2006-05-10 21:18 Alvin Ye 叶冬开 阅读(35) | 评论 (0)编辑


2006年5月9日

delphi 的分离字符串函数 split
文章来源:http://blog.csdn.net/Open2ye/archive/2006/05/08/713620.aspx

posted @ 2006-05-09 06:23 Alvin Ye 叶冬开 阅读(232) | 评论 (0)编辑

去掉Dblookupeh控件的自己填充功能
文章来源:http://blog.csdn.net/Open2ye/archive/2006/05/08/713522.aspx

posted @ 2006-05-09 05:30 Alvin Ye 叶冬开 阅读(36) | 评论 (1)编辑


posts - 13, comments - 9, trackbacks - 0, articles - 1

Copyright © Alvin Ye 叶冬开