一个简单的递归页面控件赋值的代码!~

代码
   
     
protected void BindKj(ControlCollection cl, string [] StrArray)
{
foreach (Control tb in cl)
{
if (tb.HasControls() == true )
{
BindKj(tb.Controls, StrArray);
}
if (tb.GetType() == typeof (LJControl.TextBox))
{
LJControl.TextBox tbs
= (LJControl.TextBox)tb;
if (tbs.ID == " TextBoxsA " )
{
if (StrArray != null && StrArray.Length > 0 )
for ( int i = 0 ; i < StrArray.Length; i ++ )
{
string [] s = StrArray[i].ToString().Split( ' : ' );
if (tbs.ID == s[ 0 ].ToString())
{
tbs.Text
= s[ 1 ].ToString();
break ;
}
}
}
if (tbs.ID == " TextBoxsB " )
{
if (StrArray != null && StrArray.Length > 0 )
for ( int i = 0 ; i < StrArray.Length; i ++ )
{
string [] s = StrArray[i].ToString().Split( ' : ' );
if (tbs.ID == s[ 0 ].ToString())
{
tbs.Text
= s[ 1 ].ToString();
break ;
}
}
}
if (tbs.ID == " TextBoxsC " )
{
if (StrArray != null && StrArray.Length > 0 )
for ( int i = 0 ; i < StrArray.Length; i ++ )
{
string [] s = StrArray[i].ToString().Split( ' : ' );
if (tbs.ID == s[ 0 ].ToString())
{
tbs.Text
= s[ 1 ].ToString();
break ;
}
}
}
if (tbs.ID == " TextBoxsD " )
{
if (StrArray != null && StrArray.Length > 0 )
for ( int i = 0 ; i < StrArray.Length; i ++ )
{
string [] s = StrArray[i].ToString().Split( ' : ' );
if (tbs.ID == s[ 0 ].ToString())
{
tbs.Text
= s[ 1 ].ToString();
break ;
}
}
}
}


}

 

给4个文本框打上对应的值!~

你可能感兴趣的:(递归)