#region usingusing System; using System.Collections; using System.Configuration; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel;using JI0.Common; using JI0.Web;#endregion[ assembly:TagPrefix("JI0.Web.Controls","bigo") ] namespace JI0.Web.Controls { [ DefaultProperty("Value"), ToolboxData("<{0}:MyComboBox runat=server />") ] public class MyComboBox : Control, INamingContainer {
ListBox listBox = new ListBox(); RegularExpressionValidator regexVal = new RegularExpressionValidator(); TextBox textBox = new TextBox(); ICollection dataSource = new int[] {2322,2,3}; int width = 132; int maxLength = 50; string text = "0"; bool required = false; string errorMessage = "请注意格式。"; string regularExpression = @".*"; [ Bindable(true), Category("Appearance"), DefaultValue(50), ] public int MaxLength { get{
[email protected]
[email protected]
THANKS!
[email protected]
思路:当需要用TextBox输入时将DropDownList这一列隐藏;
当需要用DropDownList选择时将TextBox隐藏。
思路:当需要用TextBox输入时将DropDownList这一列隐藏;
当需要用DropDownList选择时将TextBox隐藏这个思路就可以‘
怎么还没有发呢
using System.Collections;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;using JI0.Common;
using JI0.Web;#endregion[
assembly:TagPrefix("JI0.Web.Controls","bigo")
]
namespace JI0.Web.Controls {
[
DefaultProperty("Value"),
ToolboxData("<{0}:MyComboBox runat=server />")
]
public class MyComboBox : Control, INamingContainer {
ListBox listBox = new ListBox();
RegularExpressionValidator regexVal = new RegularExpressionValidator();
TextBox textBox = new TextBox(); ICollection dataSource = new int[] {2322,2,3};
int width = 132;
int maxLength = 50;
string text = "0";
bool required = false; string errorMessage = "请注意格式。";
string regularExpression = @".*"; [
Bindable(true),
Category("Appearance"),
DefaultValue(50),
]
public int MaxLength {
get{
return maxLength;
} set{
maxLength = value;
}
} [
Bindable(true),
Category("Appearance"),
DefaultValue(@".*"), ]
public string RegularExpression {
get{
return regularExpression;
} set{
regularExpression = value;
}
} [
Bindable(true),
Category("Appearance"),
DefaultValue(false)
]
public bool Required{
get{
return required;
} set{
required = value;
}
}
[
Bindable(true),
Category("Appearance"),
DefaultValue("请注意格式。"), ]
public ICollection DataSource {
get{
return dataSource;
} set{
dataSource = value;
}
}
[
Bindable(true),
Category("Appearance"),
DefaultValue("请注意格式。"), ]
public string ErrorMessage {
get{
return errorMessage;
} set{
errorMessage = value;
}
} [
Bindable(true),
Category("Appearance"),
DefaultValue(""), ]
public string Value {
get{
return text;
} set{
text = value;
}
}
[
Bindable(true),
Category("Appearance"),
DefaultValue(50),
Description("样式属性(宽度)width:50")
]
public int Width {
get{
return width;
} set{
width = value;
}
}
protected override void CreateChildControls() { Controls.Add(new LiteralControl("<div>"));
Controls.Add(textBox);
Controls.Add(listBox);
textBox.ID = "txt";
textBox.MaxLength = maxLength;
textBox.Attributes["style"] = "width:" + width; listBox.ID = "slt";
listBox.Attributes["style"] = "position:absolute; visibility:hidden;width:" + (width + 20);
listBox.DataSource = dataSource;
listBox.DataBind();
listBox.Rows = (listBox.Items.Count > 10 ? 10 : listBox.Items.Count);
listBox.Attributes["onBlur"] = "this.style.visibility='hidden'";
listBox.Attributes["onChange"] = "document.all['" + textBox.UniqueID +
"'].value = this.options[ this.options.selectedIndex ].text;"; string button = "<input value=▼ type=button onclick=\"___MyComboBox_Click('"
+ listBox.UniqueID + "')\">";
Controls.AddAt(2, new LiteralControl(button)); regexVal.ErrorMessage = errorMessage;
regexVal.ValidationExpression = regularExpression;
regexVal.ControlToValidate = textBox.ID; if (required) { RequiredFieldValidator reqVal = new RequiredFieldValidator();
reqVal.ErrorMessage = " **";
reqVal.IsValid = false;
// reqVal.ForeColor = System.Drawing.Color.Black;
reqVal.ControlToValidate = textBox.ID;
Controls.Add(reqVal);
} Controls.Add(regexVal); Controls.Add(new LiteralControl("<br>"));
Controls.Add(listBox);
Controls.Add(new LiteralControl("</div>")); string script = Html.TAG_START_SCRIPT + @"
function ___MyComboBox_Click(selectId) {
var ___MyCombox_Select = document.all[selectId];
___MyCombox_Select.style.visibility = 'visible';
___MyCombox_Select.focus();
}" +
Html.TAG_END_SCRIPT; if (!this.Page.IsClientScriptBlockRegistered("MyComboBox")) this.Page.RegisterClientScriptBlock("MyComboBox", script);
}
}
}