asp.net自定义一个控件 可输入的下拉框

yanghua_yanghua 2012-02-22 03:39:51
我想自定义一个控件。可输入的下拉框。但是不太会定义啊。 环境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设置样式。我都不会。希望各位大侠 指点一下呀
...全文
382 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanghua_yanghua 2012-02-24
  • 打赏
  • 举报
回复
问题已解决。http://download.csdn.net/download/himajie/2613203
谢谢各位帮忙。
冰镇宝贝321 2012-02-24
  • 打赏
  • 举报
回复
这个 是设计界面代码


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;
}
}

冰镇宝贝321 2012-02-24
  • 打赏
  • 举报
回复
我这有个 代码是
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 = "";

}

}

}
}
}
myhope88 2012-02-24
  • 打赏
  • 举报
回复
路过,帮顶下
yanghua_yanghua 2012-02-24
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 insus 的回复:]
参考(第二个搜索功能):
http://www.cnblogs.com/insus/archive/2011/11/25/2263185.html
[/Quote]
非常感谢你呀。可我想要的不是这样的啊。vs2008里的dropdownlist只能选择不能自己输入。可我也想在下拉框中没有想要的选项就自己输入的功能。所以想自己写个用户控件。
insus 2012-02-22
  • 打赏
  • 举报
回复
yanghua_yanghua 2012-02-22
  • 打赏
  • 举报
回复
我还是希望能写个用户控件。希望大家给点指导。
yanghua_yanghua 2012-02-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 xiao0326 的回复:]
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ComboBox/ComboBox.aspx
[/Quote]
我的ajax引用不进来ComboBox啊
油泼白菜 2012-02-22
  • 打赏
  • 举报
回复
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ComboBox/ComboBox.aspx
孟子E章 2012-02-22
  • 打赏
  • 举报
回复
网上有现成的
http://www.obout.com/combobox/

也可以搜索google asp.net combox control

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧