The main code of controlmanger is as follows:
Namespace beyondbit. Research. Web. UI. webcontrols. Common. databinding
{
[
Provideproperty ("datasource", typeof (Control )),
Provideproperty ("propertyname", typeof (Control )),
]
Public class controlmanager: controlmanagerbase
{
Public controlmanager (){}
# Region extended attributes
[
Defaultvalue ("")
]
Public String getdatasource (Control)
{
Foreach (controlmanagersetting setting in settings)
{
If (control. ID = Setting. Parent)
{
Return setting. datasource;
}
}
Return string. empty;
}
Public void setdatasource (Control, string value)
{
If (value = NULL)
{
Value = string. empty;
}
Controlmanagersetting newsetting = NULL;
Foreach (controlmanagersetting setting in settings)
{
If (setting. Parent = control. ID)
{
Newsetting = setting;
Break;
}
}
If (newsetting = NULL)
{
If (value! = "")
{
Newsetting = new controlmanagersetting ();
Newsetting. Parent = control. ID;
Newsetting. datasource = value;
Settings. Add (newsetting );
}
}
Else
{
If (value! = "")
{
Newsetting. datasource = value;
}
Else
{
Settings. Remove (newsetting );
}
}
Yydesignerofchange ();
}
[
Defaultvalue ("")
]
Public String getpropertyname (Control)
{
Foreach (controlmanagersetting setting in settings)
{
If (control. ID = Setting. Parent)
{
Return setting. propertyname;
}
}
Return string. empty;
}
Public void setpropertyname (Control, string value)
{
If (value = NULL)
{
Value = string. empty;
}
Controlmanagersetting newsetting = NULL;
Foreach (controlmanagersetting setting in settings)
{
If (setting. Parent = control. ID)
{
Newsetting = setting;
Break;
}
}
If (newsetting = NULL)
{
If (value! = "")
{
Newsetting = new controlmanagersetting ();
Newsetting. Parent = control. ID;
Newsetting. propertyname = value;
Settings. Add (newsetting );
}
}
Else
{
If (value! = "")
{
Newsetting. propertyname = value;
}
Else
{
Settings. Remove (newsetting );
}
}
Yydesignerofchange ();
}
# Endregion
# Region dynamic binding method
Public void userdatabind (Object OBJ)
{
Foreach (Control in parent. Controls)
{
If (control is system. Web. UI. webcontrols. textbox)
{
System. Web. UI. webcontrols. textbox = control as system. Web. UI. webcontrols. textbox;
Foreach (controlmanagersetting setting in settings)
{
If (setting. Parent = control. ID)
{
Type T = obj. GetType ();
Propertyinfo P = T. getproperty (setting. propertyname );
Textbox. Text = P. getvalue (OBJ, null). tostring (). Trim ();
}
}
// You can process other types of controls separately.
If (control is system. Web. UI. webcontrols. Label)
..........
}
}
}
Public object binddatarefresh (Object OBJ)
{
Foreach (Control in parent. Controls)
{
If (control is system. Web. UI. webcontrols. textbox)
{
System. Web. UI. webcontrols. textbox = control as system. Web. UI. webcontrols. textbox;
Foreach (controlmanagersetting setting in settings)
{
If (setting. Parent = control. ID)
{
Type T = obj. GetType ();
Propertyinfo P = T. getproperty (setting. propertyname );
P. setvalue (OBJ, textbox. Text, null );
}
}
........
}
}