當前位置:編程學習大全網 - 電腦編程 - 請編程遍歷頁面上所有TextBox控件並給它賦值為string.Empty(用C#語言)

請編程遍歷頁面上所有TextBox控件並給它賦值為string.Empty(用C#語言)

前臺的代碼:

foreach (Control txtobj in this.Page.Controls)

{

if (txtobj.GetType().Name == "TextBox")

{

// ((TextBox)txtobj).Text = "";//這是第壹種方法賦值,第二種在下面

TextBox tb = new TextBox();

tb = (TextBox)this.FindControl(txtobj.ID); nbsp;

tb.Text = string.Empty;

}

後臺代碼:

foreach(Control ctl in this.Controls)

{

if(ctl is TextBox){

(ctl as TextBox).Text = string.Empty;

}}

}

  • 上一篇:關於C#的windows窗體編程代碼,最後的提示是“應該輸入;”,這是什麽?
  • 下一篇:在PLC200中如何實現整數每隔3秒加壹壹直加到50
  • copyright 2024編程學習大全網