Source code of webcontrolmanager

Source: Internet
Author: User

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 );
}
}
........
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.