首页 > Web开发 > 详细

动态向页面添加控件和使用正则表达式的代码

时间:2015-12-07 07:03:06      阅读:233      评论:0      收藏:0      [点我收藏+]
复制代码 代码如下:

namespace WebCode
{
public partial class _default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String str = "这是一个测试文件<{config name=\"pagetitle1\"}>,一个标签的解析<{config name=\"pagetitle2\" count=\"2\"}>过程";
Label mylabel = new Label();
mylabel.ID = "display";
mylabel.Text = this.myReplace(str);
Page.Form.Controls.Add(mylabel);
}
protected String myReplace(String str)
{
String pattern = @"\<\{(.*?)\}\>";
Regex p = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection m = p.Matches(str);
String matchs = "";
for (int i = 0; i < m.Count; i++)
{
matchs += "," + m[i];
}
return matchs.Substring(1);
}
}
}

Page.Form.Controls.Add
向页面中Form节点的尾部添加控件。
using System.Text.RegularExpressions;
使用正则表达式要使用的类

动态向页面添加控件和使用正则表达式的代码

原文:http://www.jb51.net/article/19641.htm

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!