加入收藏 | 设为首页 | 会员中心 | 我要投稿 51站长网 (https://www.51zhanzhang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
站内搜索:
当前位置: 首页 > 站长学院 > Asp教程 > 正文

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

发布时间:2021-07-13 10:03:25 所属栏目:Asp教程 来源:互联网
导读:动态向页面添加控件和使用正则表达式的实现代码。


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;
使用正则表达式要使用的类

(编辑:ASP站长)

【免责声明】本站内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

    相关内容
    未处理完善
      无相关信息
    未处理完善