发布于 2016-06-07 00:18:28 | 81 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

ASP.NET

ASP.NET 是.NET FrameWork的一部分,是一项微软公司的技术,是一种使嵌入网页中的脚本可由因特网服务器执行的服务器端脚本技术,它可以在通过HTTP请求文档时再在Web服务器上动态创建它们。 指 Active Server Pages(动态服务器页面) ,运行于 IIS(Internet Information Server 服务,是Windows开发的Web服务器)之中的程序 。


页面内有许多控件,在清理的过程中很费时间,于是写了这么一个方法,可以自定义清空控件的类型,感兴趣的朋友可以参考下哈
由于项目收尾,最近忙着做一些方法的优化,整理了一些分享给大家。

当页面内有许多控件,我们在需要清空其值的时候,一个个清空未免太麻烦。于是写了这么一个方法,可以自定义清空控件的类型,灵活应对业务需求。
 
/// <summary>重置方法控件类型枚举</summary> 
/// <remarks>求知域http://www.qqextra.com 2012-12-28</remarks> 
public enum ReSetType 
{ 
/// <summary> 
/// TextBox 
/// </summary> 
TXT, 
/// <summary> 
/// DropDownList 
/// </summary> 
DDL, 
/// <summary> 
/// RadioButtonList 
/// </summary> 
RBL, 
/// <summary> 
/// 全部ReSetType类型 
/// </summary> 
ALL 
} 
/// <summary>重置控件的值</summary> 
/// <remarks>求知域http://www.qqextra.com 2012-12-28</remarks> 
/// <param name="control">this</param> 
/// <param name="rst">ReSetType.ALL为清空ReSetType枚举中包含的所有控件类型</param> 
public static void ReSet(Control control, params ReSetType[] rst) 
{ 
bool blTxt = false; 
bool blDdl = false; 
bool blRbl = false; 
foreach (ReSetType type in rst) 
{ 
if (type == ReSetType.ALL) 
{ 
blTxt = true; 
blDdl = true; 
blRbl = true; 
break; 
} 
else 
if (type == ReSetType.TXT) 
blTxt = true; 
else if (type == ReSetType.DDL) 
blDdl = true; 
else if (type == ReSetType.RBL) 
blRbl = true; 
} 
foreach (Control c in control.Controls) 
{ 
//文本框 
if (c is TextBox && blTxt == true) 
{ 
((TextBox)c).Text = ""; 
} 
else 
//下拉列表 
if (c is DropDownList && blDdl == true) 
{ 
DropDownList ddl = (DropDownList)c; 
if (ddl.Items.Count > 0) 
{ 
ddl.SelectedIndex = 0; 
} 
} 
else 
//单选按钮列表 
if (c is RadioButtonList && blRbl == true) 
{ 
((RadioButtonList)c).SelectedIndex = -1; 
} 
else 
if (c.HasControls()) 
{ 
//递归 
ReSet(c, rst); 
} 
} 
} 


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务