public void ControlsSetValue(string ControlsId, object Value)
{
var Controls = Page.FindControl(ControlsId);
if (Controls != null)
{
if (typeof(CheckBox) == Controls.GetType())
{
((CheckBox)Controls).Checked = Value.ToString() == "1" ? true : false;
}
else if (typeof(TextBox) == Controls.GetType())
{
((TextBox)Controls).Text = Value.ToString();
}
}
}
public string ControlsGetValue(string ControlsId)
{
var Controls = Page.FindControl(ControlsId);
string Value = "";
if (Controls != null)
{
if (typeof(CheckBox) == Controls.GetType())
{
Value = ((CheckBox)Controls).Checked == true ? "1" : "0";
}
else if (typeof(TextBox) == Controls.GetType())
{
Value = ((TextBox)Controls).Text;
}
}
return Value;
}
foreach (DataRow dr in dt.Rows) {
foreach (DataColumn dc in dt.Columns) {
ControlsSetValue("old_"+dc.ColumnName, dr[dc.ColumnName]);
}
public string GetValue<T>(T t)
{
string tStr = string.Empty;
if (t == null)
{
return tStr;
}
System.Reflection.PropertyInfo[] properties = t.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
if (properties.Length <= 0)
{
return tStr;
}
foreach (System.Reflection.PropertyInfo item in properties)
{
string name = item.Name; //名称
object value = item.GetValue(t, null); //值
ControlsSetValue(name, value.ToString());
}
return tStr;
}
public string SetValue<T>(T objSrc)
{
string valueTo = "";
string tStr = string.Empty;
if (objSrc == null)
{
return tStr;
}
System.Reflection.PropertyInfo[] properties = objSrc.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
if (properties.Length <= 0)
{
return tStr;
}
foreach (System.Reflection.PropertyInfo info in properties)
{
string name = info.Name; //名称
valueTo = ControlsGetValue(name);
if (info != null)//存在而且值不相等,就修改
{
object objValue = info.GetValue(objSrc, null);
string valueSrc = objValue == null ? "" : objValue.ToString();
if (info.PropertyType == typeof(System.Decimal))
{
info.SetValue(objSrc, Convert.ToDecimal(valueTo), null);
}
else if (info.PropertyType == typeof(System.Int32))
{
info.SetValue(objSrc, Convert.ToInt32(valueTo), null);
}
else if (info.PropertyType == typeof(System.String))
{
info.SetValue(objSrc, valueTo, null);
}
else if (info.PropertyType == typeof(System.DateTime))
{
if (valueTo == "")
{
info.SetValue(objSrc, null, null);
}
else
{
info.SetValue(objSrc, Convert.ToDateTime(valueTo), null);
}
}
}
}
return tStr;
}