表布一个比Lostinet的ComboBox控件起码简单十倍,但功能强大的combobox控件,原创的。
http://expert.csdn.net/Expert/topic/1868/1868077.xml?temp=.1306269发布一个简单的ComboBox的原代码,我想对正在学控件编程的朋友都有参考用途:
http://expert.csdn.net/Expert/topic/1716/1716109.xml?temp=.384411

解决方案 »

  1.   

    http://chs.gotdotnet.com/quickstart/aspplus/doc/webctrlauthoring.aspx
      

  2.   

    http://www.codeproject.com上一大把
      

  3.   

    只有codebehind,用c#写的,实现方法:通过webservice,函数接口是
    DataSet GetNewsForNewsPanel((int)this.NewsNum,this.NewsKind,this.BeginTime,this.EndTime),返回一个数据集,
    控件的功能就是显示数据集中的新闻namespace NewsList
    {
    using System;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Web.UI;
    using System.Collections; /// <summary>
    /// NewsList 的摘要说明。
    /// </summary>
    public abstract class NewsList : System.Web.UI.UserControl
    {
    private WebApplication4.Cnews.CNews DataSource;//web service实例
    private DataSet news;//保存从web service获得满足条件的新闻
    private string title="=demo=";//新闻标题
    private string newskind="sports";//新闻种类
    private uint newsnum=5;//新闻数量
    private DateTime begintime=DateTime.MinValue;//起始时间
    private DateTime endtime=DateTime.Now;//结束时间
    private string height="240px";//控件高度
    private string width="298px";//控件宽度
    private uint maxLineWordCount=20;//一行最多能显示的字数
    public string Title
    {
    get
    {
    return title;
    }
    set
    {
    title=value;
    }
    }
    public string NewsKind
    {
    get
    {
    return newskind;
    }
    set
    {
    newskind=value;
    }
    }
    public uint NewsNum
    {
    get
    {
    return newsnum;
    }
    set
    {
    newsnum=value;
    }
    }
    public DateTime BeginTime
    {
    get
    {
    return begintime;
    }
    set
    {
    begintime=value;
    }
    }
    public DateTime EndTime
    {
    get
    {
    return endtime;
    }
    set
    {
    endtime=value;
    }
    }
    public string Height
    {
    get
    {
    return height;
    }
    set
    {
    height=value;
    }
    }
    public string Width
    {
    get
    {
    return width;
    }
    set
    {
    width=value;
    }
    }
    public uint MaxLineWordCount
    {
    get
    {
    return maxLineWordCount;
    }
    set
    {
    maxLineWordCount=value;
    }
    }
    protected override void Render(HtmlTextWriter output)
    {
    int maxRows = (int)NewsNum;
    const int maxCols = 1;
    output.WriteLine();
    //output.WriteFullBeginTag("h1");
    //output.Write("Using the HtmlTextWriterClass");
    //output.WriteEndTag("h1");
    // ...
    output.Write("<div name="+this.UniqueID+" style='background-color:white;border-style:Redge;border-color:blue;height:"+this.Height+";width:"+this.Width+";'"+">");
    output.WriteLine();
    output.Indent++; output.WriteBeginTag("table");
    //output.AddStyleAttribute(HtmlTextWriterStyle.FontWeight, "bold");
    //output.AddStyleAttribute(HtmlTextWriterStyle.FontFamily, "verdana");
    //output.AddStyleAttribute(HtmlTextWriterStyle.FontSize, "14pt");
    //output.AddStyleAttribute(HtmlTextWriterStyle.Width,"295px");
    //output.Write("style='font-size:x-small;OVERFLOW:hidden;WIDTH:295px;HEIGHT:167px;TEXT-ALIGN:center'");
    output.WriteAttribute("border","0");
    output.Write(" style='WIDTH:"+this.Width+";HEIGHT:"+Convert.ToString(20*this.NewsNum)+"px;'");
    output.Write(HtmlTextWriter.TagRightChar);
    output.WriteLine();
    output.WriteFullBeginTag("tr");
    output.WriteLine(); output.Indent++;
    output.WriteBeginTag("td");
    output.WriteAttribute("valign","top");
    output.WriteAttribute("bgcolor","lightblue");
    output.Write(" style='height:20px;'");
    output.Write(HtmlTextWriter.TagRightChar);
    //output.Write("Cell (" + i.ToString() + "," + j.ToString() + ")" );
    output.Write(this.Title);
    output.WriteEndTag("td");
    output.WriteLine(); output.Indent--;
    output.WriteEndTag("tr");
    output.WriteLine();
    output.Indent++;
    for (int i=0; i<maxRows; i++) 
    { output.WriteFullBeginTag("tr");
    output.WriteLine(); output.Indent++;
    for (int j=0; j<maxCols; j++) 
    { output.WriteBeginTag("td");
    output.WriteAttribute("valign","top");
    output.WriteAttribute("bgcolor","white");
    output.Write(" style='height:25px;'");
    output.Write(HtmlTextWriter.TagRightChar);
    //output.Write("Cell (" + i.ToString() + "," + j.ToString() + ")" ); output.WriteLine();
    output.Write(" <a href="+"'http://wallffpp/WebApplication4/WebForm1.aspx?NewsID'>");
    if(news.Tables["新闻"].Rows[i].ItemArray[1].ToString().Length>(int)(this.MaxLineWordCount))
    {
    output.Write(news.Tables["新闻"].Rows[i].ItemArray[1].ToString().Substring(0,(int)(this.MaxLineWordCount)));
    output.Write("...");
    }
    else
    {
    output.Write(news.Tables["新闻"].Rows[i].ItemArray[1].ToString());
    }
    output.Write("</a>");
    output.WriteLine();
    output.WriteEndTag("td");
    output.WriteLine();
    } output.Indent--;
    output.WriteEndTag("tr");
    output.WriteLine();
    }
    output.Indent--; // ...
    output.WriteEndTag("table");
    output.WriteLine();
    output.Indent--;
    output.Write("</div>"); }
    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    DataSource=new WebApplication4.Cnews.CNews();
    news=DataSource.GetNewsForNewsPanel((int)this.NewsNum,this.NewsKind,this.BeginTime,this.EndTime);
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// 设计器支持所需的方法 - 不要使用
    /// 代码编辑器修改此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion
    }
    }
      

  4.   

    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using System.Resources;
    using System.Web.UI.Design;namespace drk.WebControls { /// <summary>
    /// Provides a numeric up-down control.
    /// </summary>
    /// <res>
    /// This control is generally combined with a compare validator used to ensure only numbers are entered.
    /// </res>
    /// <example>
    /// Here is a simple example using the UpDown control.
    /// <code><![CDATA[
    /// <%@ Register TagPrefix="mbud" Namespace="MetaBuilders.WebControls" Assembly="MetaBuilders.WebControls.UpDown" %>
    /// <html><body><form runat="server">
    /// <p>
    /// <asp:CompareValidator runat="server" ControlToValidate="UpDown1" Type="Double" Operator="DataTypeCheck" ErrorMessage="Number Required" Display="Static" />
    /// <mbud:UpDown id="UpDown1" runat="server" Increment="1" UpImageUrl="up.gif" DownImageUrl="down.gif" />
    /// <asp:Button runat="server" text="smack" />
    /// </p>
    /// </form></body></html>
    /// ]]></code>
    /// </example>
    [
    DefaultEvent("TextChanged"),
    DefaultProperty("Text"),
    ValidationPropertyAttribute("Text")
    ]
    public class UpDown : System.Web.UI.WebControls.WebControl, INamingContainer { /// <summary>
    /// Creates a new instance of the <see cref="UpDown"/> control.
    /// </summary>
    public UpDown() : base() {
    } #region Style transference
    /// <summary>
    /// Applies <see cref="WebControl.BackColor"/> to the Textbox area of the control.
    /// </summary>
    public override System.Drawing.Color BackColor {
    get {
    this.EnsureChildControls();
    return this.textBox.BackColor;
    }
    set {
    this.EnsureChildControls();
    this.textBox.BackColor = value;
    }
    } /// <summary>
    /// Applies <see cref="WebControl.BorderColor"/> to the Textbox area of the control.
    /// </summary>
    public override System.Drawing.Color BorderColor {
    get {
    this.EnsureChildControls();
    return this.textBox.BorderColor;
    }
    set {
    this.EnsureChildControls();
    this.textBox.BorderColor = value;
    }
    } /// <summary>
    /// Applies <see cref="WebControl.BorderStyle"/> to the Textbox area of the control.
    /// </summary>
    public override System.Web.UI.WebControls.BorderStyle BorderStyle {
    get {
    this.EnsureChildControls();
    return this.textBox.BorderStyle;
    }
    set {
    this.EnsureChildControls();
    this.textBox.BorderStyle = value;
    }
    } /// <summary>
    /// Applies <see cref="WebControl.BorderWidth"/> to the Textbox area of the control.
    /// </summary>
    public override System.Web.UI.WebControls.Unit BorderWidth {
    get {
    this.EnsureChildControls();
    return this.textBox.BorderWidth;
    }
    set {
    this.EnsureChildControls();
    this.textBox.BorderWidth = value;
    }
    } /// <summary>
    /// Applies <see cref="WebControl.CssClass"/> to the Textbox area of the control.
    /// </summary>
    public override string CssClass {
    get {
    this.EnsureChildControls();
    return this.textBox.CssClass;
    }
    set {
    this.EnsureChildControls();
    this.textBox.CssClass = value;
    }
    } /// <summary>
    /// Applies <see cref="WebControl.Font"/> to the Textbox area of the control.
    /// </summary>
    public override System.Web.UI.WebControls.FontInfo Font {
    get {
    this.EnsureChildControls();
    return this.textBox.Font;
    }
    } /// <summary>
    /// Applies <see cref="WebControl.ForeColor"/> to the Textbox area of the control.
    /// </summary>
    public override System.Drawing.Color ForeColor {
    get {
    this.EnsureChildControls();
    return this.textBox.ForeColor;
    }
    set {
    this.EnsureChildControls();
    this.textBox.ForeColor = value;
    }
    } /// <summary>
    /// Applies <see cref="WebControl.Height"/> to the Textbox area of the control.
    /// </summary>
    public override System.Web.UI.WebControls.Unit Height {
    get {
    this.EnsureChildControls();
    return this.textBox.Height;
    }
    set {
    this.EnsureChildControls();
    this.textBox.Height = value;
    }
    }
    /// <summary>
    /// Applies <see cref="WebControl.TabIndex"/> to the Textbox area of the control.
    /// </summary>
    public override short TabIndex {
    get {
    this.EnsureChildControls();
    return this.textBox.TabIndex;
    }
    set {
    this.EnsureChildControls();
    this.textBox.TabIndex = value;
    }
    } /// <summary>
    /// Applies <see cref="WebControl.ToolTip"/> to the Textbox area of the control.
    /// </summary>
    public override string ToolTip {
    get {
    this.EnsureChildControls();
    return this.textBox.ToolTip;
    }
    set {
    this.EnsureChildControls();
    this.textBox.ToolTip = value;
    }
    }
      

  5.   

    /// <summary>
    /// Applies <see cref="WebControl.Width"/> to the Textbox area of the control.
    /// </summary>
    public override System.Web.UI.WebControls.Unit Width {
    get {
    this.EnsureChildControls();
    return this.textBox.Width;
    }
    set {
    this.EnsureChildControls();
    this.textBox.Width = value;
    }
    }
    #endregion /// <summary>
    /// Gets or sets the image to display for the "Up" button.
    /// </summary>
    /// <res>Clicking on this image will increment the value.</res>
    [
    Editor("System.Web.UI.Design.ImageUrlEditor","System.Drawing.Design.UITypeEditor"),
    Bindable(true),
    Category("Appearance"),
    DefaultValue("")
    ]
    public virtual String UpImageUrl {
    get {
    this.EnsureChildControls();
    return this.up.ImageUrl;
    }
    set {
    this.EnsureChildControls();
    this.up.ImageUrl = value;
    }
    } /// <summary>
    /// Gets or sets the image to display for the "Down" button.
    /// </summary>
    /// <res>Clicking on this image will decrement the value.</res>
    [
    Editor("System.Web.UI.Design.ImageUrlEditor","System.Drawing.Design.UITypeEditor"),
    Bindable(true),
    Category("Appearance"),
    DefaultValue("")
    ]
    public virtual String DownImageUrl {
    get {
    this.EnsureChildControls();
    return this.down.ImageUrl;
    }
    set {
    this.EnsureChildControls();
    this.down.ImageUrl = value;
    }
    } /// <summary>
    /// Gets or sets the displayed value of the control.
    /// </summary>
    [
    Bindable(true),
    Category(""),
    DefaultValue("")
    ]
    public virtual String Text {
    get {
    this.EnsureChildControls();
    return this.textBox.Text;
    }
    set {
    this.EnsureChildControls();
    this.textBox.Text = value;
    }
    } /// <summary>
    /// Gets or sets the amount which the up or down buttons will change the value.
    /// </summary>
    [
    Bindable(true),
    Category("Behavior"),
    DefaultValue(10)
    ]
    public virtual Decimal Increment {
    get {
    Object savedState = this.ViewState["Increment"];
    if ( savedState != null ) {
    return (Decimal)savedState;
    }
    return 10;
    }
    set {
    this.ViewState["Increment"] = value;
    }
    } /// <summary>
    /// Occurs when the <see cref="UpDown.Text"/> property has changed.
    /// </summary>
    public event EventHandler TextChanged; /// <summary>
    /// Raises the <see cref="UpDown.TextChanged"/> event.
    /// </summary>
    protected virtual void OnTextChanged( EventArgs e ) {
    if ( this.TextChanged != null ) {
    this.TextChanged( this, e );
    }
    } private void bubbleTextChanged( Object sender, EventArgs e ) {
    this.OnTextChanged(e);
    } private Table layout;
    private TextBox textBox;
    private System.Web.UI.WebControls.HyperLink up;
    private System.Web.UI.WebControls.HyperLink down; /// <summary>
    /// Overrides <see cref="Control.CreateChildControls"/>
    /// </summary>
    protected override void CreateChildControls() {
    layout = new Table();
    textBox = new TextBox();
    up = new HyperLink();
    down = new HyperLink(); this.textBox.TextChanged += new EventHandler( bubbleTextChanged );
    this.textBox.Style["text-align"] = "right";
    this.textBox.ID = "textBox";
    this.textBox.Style["margin"] = "0px"; this.up.Text = "up";
    this.down.Text = "down";
    layout.CellPadding = 0;
    layout.CellSpacing = 0;
    layout.BorderWidth = 0;
    layout.Rows.Add( new TableRow() );
    layout.Rows.Add( new TableRow() );
    layout.Rows[0].Cells.Add( new TableCell() );
    layout.Rows[0].Cells[0].RowSpan = 2;
    layout.Rows[0].Cells[0].Attributes["valign"] = "middle";
    layout.Rows[0].Cells.Add( new TableCell() );
    layout.Rows[1].Cells.Add( new TableCell() ); layout.Rows[0].Cells[0].Controls.Add( textBox );
    layout.Rows[0].Cells[1].Controls.Add( up );
    layout.Rows[1].Cells[ layout.Rows[1].Cells.Count - 1].Controls.Add( down ); this.Controls.Add( layout );
    } /// <summary>
    /// Overrides <see cref="Control.OnPreRender"/>
    /// </summary>
    protected override void OnPreRender(System.EventArgs e) {
    base.OnPreRender(e);
    this.RegisterClientScript();
    } /// <summary>
    /// Overrides <see cref="Control.Render"/>
    /// </summary>
    protected override void Render(HtmlTextWriter writer ) {
    this.EnsureChildControls();
    this.layout.Height = this.Height;
    this.textBox.Enabled = this.Enabled;
    this.up.Enabled = this.Enabled;
    this.down.Enabled = this.Enabled;
    base.Render(writer);
    } /// <summary>
    /// Registers ClientScript with the Page.
    /// </summary>
    protected virtual void RegisterClientScript() {
    if ( this.Enabled ) {
    if( !Page.IsClientScriptBlockRegistered( "yearUpDown Library" ) ) {
    ResourceManager manager = new ResourceManager( this.GetType() );
    //从系统类库中抓取往页面写入要用到的JSP函数.
    String script = manager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true).GetString("LibraryScript");
    this.Page.RegisterClientScriptBlock("yearUpDown Library", script );
    } this.up.NavigateUrl = "javascript: UpDown_Increment( '" + this.textBox.UniqueID + "', " + this.Increment.ToString() + " );";
    this.down.NavigateUrl = "javascript: UpDown_Decrement( '" + this.textBox.UniqueID + "', " + this.Increment.ToString() + " );";
    }
    } }
    }