怎麼限制文字框不能輸入中文漢字?在ASP中怎麼改變下拉列表dropdownlist的樣式
- 2022-08-15
onpaste = “return regInput(this, /^\d*\。?\d{0,2}$/, window。clipboardData。getData(‘Text’))”
ondrop = “return regInput(this, /^\d*\。?\d{0,2}$/, event。dataTransfer。getData(‘Text’))” VALUE=“0”>
不能輸入漢字
自己仔細看屬性dropdownlist裡面有個屬性的作用就是幫定資料的型別 還有的就是 顯示的STYLE
獨自等待 回答得很全,頂一個
第一個 用正則表示式
第二個 樣式
這就行了,在〈BODY〉裡輸入
【第一個問題】
sub classAndRegExp()
set wolf = new CNWord
wolf。str = input1。value
msgbox “含有中文數” & wolf。CNcount
msgbox “含有中文塊數” & wolf。CNBlockCount
msgbox “第2箇中文塊是——->” & wolf。CN(2)
msgbox “第1箇中文塊出現的位置是——->” & wolf。CNIndex(1)
set wolf = nothing
end sub
class CNWord
public str
private sub Class_Initialize()
set regEx =new RegExp
regEx。IgnoreCase = True ‘設定是否區分大小寫。
regEx。Global = True ’設定全域性可用性。
end sub
private regEx
Property get CN(x)
dim Arr()
dim maxBound : maxBound = CNBlockCount
redim Arr(maxBound)
dim i:i=1
dim Match
For each Match in regEx。Execute(str)
Arr(i) = Match
i = i + 1
next
if x<=maxBound then CN = Arr(x)
End Property
Property get CNIndex(x)
dim Arr()
dim maxBound : maxBound = CNBlockCount
redim Arr(maxBound)
dim i:i=1
dim Match
For each Match in regEx。Execute(str)
Arr(i) = Match。FirstIndex + 1
i = i + 1
next
if x<=maxBound then CNIndex = Arr(x)
End Property
Property get CNcount
‘返回含有中文的字數
regEx。Pattern = “[\u4e00-\u9fa5]”
CNcount = findCHNnum()
End Property
Property get CNBlockCount
’返回含有中文的塊數
regEx。Pattern = “[\u4e00-\u9fa5]+”
CNBlockCount = findCHNnum()
End Property
private function findCHNnum()
findCHNnum = regEx。Execute(str)。count
end function
private sub Class_Terminate()
set regEx = nothing
end sub
end class
【第二個問題】有兩種方法
private void Page_Load(object sender, System。EventArgs e)
{
if (!IsPostBack)
{
bindtodropdownlist1();//第一種方法
bindtodropdownlist2();//第二種方法
}
}
//第一種方法
private void bindtodropdownlist1()
{
string connstring=“data source=SINOSOFT-SERVER;initial catalog=kmsdb;user id=mbm;password=mbm”;
string querystring=“select distinct cDepartmentname from t_Department”;
SqlConnection myconn=new SqlConnection(connstring);
myconn。Open();
SqlDataAdapter myadapter=new SqlDataAdapter(querystring,myconn);
DataSet ds=new DataSet();
myadapter。Fill(ds,“t_Department”);
myconn。Close();
DropDownList1。DataSource=ds。Tables[0]。DefaultView;
DropDownList1。DataValueField=ds。Tables[“t_Department”]。Columns“cDepartmentName”]。ToString();
DropDownList1。DataBind();
}
//第二種方法
private void bindtodropdownlist2()
{
string connstring=“data source=SINOSOFT-SERVER;initial catalog=kmsdb;user id=kms;password=kms”;
string querystring=“select distinct cDepartmentname from t_Department”;
SqlConnection myconn=new SqlConnection(connstring);
myconn。Open();
SqlCommand myCommand = new SqlCommand(querystring,myconn);
SqlDataReader myReader;
myReader = myCommand。ExecuteReader();// Always call Read before accessing data。
while (myReader。Read())
{
DropDownList2。Items。Add(new ListItem(myReader。GetString(0),myReader。GetString(0)));
}
myReader。Close();
myconn。Close();
}