2017-11-17 1 views
0

完全なWebcontrolをその型を決定することによってそのWebControlの値を設定する参照付きのメソッドに渡す必要があります。完全なWebcontrolを渡すには?

enter code here 
public void SetValue(ref WebControl,string value){ 
     Type t=WebControl.Gettype(); 

     if(t.Name== "TextBox"){ 
      // set TextBox Value 
     } 
     else if (t.Name=="Dropdown"){ 
     // set Dropdown value. 
    } 

}

////////////// aspx.csファイルにおける上記関数の呼び出し。

SetValue(ref txEmployee,"123"); 

私はasp.net Webformsを使用しています。

答えて

0

オブジェクトへのボックスコントロールとオブジェクト自体での作業。

//Method 
public void SetValue(ref object oWebControl,string value){ 
     switch (oWebControl.GetType().Name) 
     { 
      case "RadioButton": { /*do stuff here*/} break; 
      case "DropDownList": { /*do stuff here*/} break; 
      case "TextBox": { /*do here*/} break; 
      /*more checking here*/ 
      default: break; 
     } 
    } 

//Box the control (Boxing) 
//For RadioButton 
object o = RadioButton as object; 
//For DropDownList 
object o = DropDownList as object; 
//For TextBox 
object o = TextBox as object; 
/*more control here*/ 

//Call Method 
SetValue(ref o,"123"); 

私はこれがあなたが探していることを望みます。

関連する問題