当前位置: 代码迷 >> ASP.NET >> asp.net自定义一个控件 可输入的下拉框,该怎么处理
  详细解决方案

asp.net自定义一个控件 可输入的下拉框,该怎么处理

热度:427   发布时间:2013-02-25 00:00:00.0
asp.net自定义一个控件 可输入的下拉框
我想自定义一个控件。可输入的下拉框。但是不太会定义啊。 环境vs2008

 <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>

<span style="width:18px;border:0px solid red; position:relative; ">
  <asp:DropDownList ID="DropDownList1" runat="server" ></asp:DropDownList>
</span>
 
还要对span设置样式。我都不会。希望各位大侠 指点一下呀

------解决方案--------------------------------------------------------
网上有现成的
http://www.obout.com/combobox/

也可以搜索google asp.net combox control
------解决方案--------------------------------------------------------
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ComboBox/ComboBox.aspx
------解决方案--------------------------------------------------------
参考(第二个搜索功能):
http://www.cnblogs.com/insus/archive/2011/11/25/2263185
------解决方案--------------------------------------------------------
路过,帮顶下
------解决方案--------------------------------------------------------
我这有个 代码是
C# code
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace Ex060{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)        {            //if (comboBox1.Text != "")            //{            //   string newItem=comboBox1.Text.Trim();             //    for (int i = 0; i < comboBox1.Items.Count; i++)            //    {            //        if (string.Compare(newItem, comboBox1.Items[i].ToString()) == 1)            //        {            //            MessageBox.Show("组合框中已有相同项,不能再添加!");            //            return;            //        }            //        else            //            comboBox1.Items.Add(comboBox1.Text.Trim());            //    }                                //}        }        private void btnAdd_Click(object sender, EventArgs e)        {            if (comboBox1.Text != "")            {                string newItem = comboBox1.Text.Trim();//获取输入文本                bool flag = false;//标识变量                for (int i = 0; i < comboBox1.Items.Count; i++)                {                  //判断是否有相同项                    if (string.Compare(newItem, comboBox1.Items[i].ToString()) == 0)                    {                        flag = true;                        MessageBox.Show("已经有相同项,不能再添加");                    }                                   }                if (flag == false)                {                                   comboBox1.Items.Add(newItem);//将输入文本添加到项中                  comboBox1.Text = "";                }            }        }    }}
------解决方案--------------------------------------------------------
这个 是设计界面代码

C# code
namespace Ex060{    partial class Form1    {        /// <summary>        /// 必需的设计器变量。        /// </summary>        private System.ComponentModel.IContainer components = null;        /// <summary>        /// 清理所有正在使用的资源。        /// </summary>        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>        protected override void Dispose(bool disposing)        {            if (disposing && (components != null))            {                components.Dispose();            }            base.Dispose(disposing);        }        #region Windows 窗体设计器生成的代码        /// <summary>        /// 设计器支持所需的方法 - 不要        /// 使用代码编辑器修改此方法的内容。        /// </summary>        private void InitializeComponent()        {            this.label1 = new System.Windows.Forms.Label();            this.comboBox1 = new System.Windows.Forms.ComboBox();            this.btnAdd = new System.Windows.Forms.Button();            this.SuspendLayout();            //             // label1            //             this.label1.AutoSize = true;            this.label1.Location = new System.Drawing.Point(40, 53);            this.label1.Name = "label1";            this.label1.Size = new System.Drawing.Size(29, 12);            this.label1.TabIndex = 0;            this.label1.Text = "年级";            //             // comboBox1            //             this.comboBox1.FormattingEnabled = true;            this.comboBox1.Items.AddRange(new object[] {            "2004级",            "2005级"});            this.comboBox1.Location = new System.Drawing.Point(93, 53);            this.comboBox1.Name = "comboBox1";            this.comboBox1.Size = new System.Drawing.Size(121, 20);            this.comboBox1.TabIndex = 1;            this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);            this.comboBox1.TextChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);            //             // btnAdd            //             this.btnAdd.Location = new System.Drawing.Point(93, 99);            this.btnAdd.Name = "btnAdd";            this.btnAdd.Size = new System.Drawing.Size(75, 23);            this.btnAdd.TabIndex = 2;            this.btnAdd.Text = "添加";            this.btnAdd.UseVisualStyleBackColor = true;            this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);            //             // Form1            //             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;            this.ClientSize = new System.Drawing.Size(265, 156);            this.Controls.Add(this.btnAdd);            this.Controls.Add(this.comboBox1);            this.Controls.Add(this.label1);            this.Name = "Form1";            this.Text = "根据输入增加选项";            this.ResumeLayout(false);            this.PerformLayout();        }        #endregion        private System.Windows.Forms.Label label1;        private System.Windows.Forms.ComboBox comboBox1;        private System.Windows.Forms.Button btnAdd;    }}
  相关解决方案