如何在 ASP.NET 中动态创建新的超链接? [英] How do I dynamically create new Hyperlinks in ASP.NET?

查看:26
本文介绍了如何在 ASP.NET 中动态创建新的超链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将解释我想要实现的目标:

I'll explain what I'm trying to achieve:

我想要一种情况,通过在后面的代码中循环创建控件,我可以创建任意数量的控件.我可以在使用 PHP 时通过混合 PHP 代码和 HTML 代码来做到这一点.这允许我动态生成实际的 HTML 标签.

I want to have a situation where I can create as many controls as I want by creating them in a loop in the code behind. I can do this while using PHP, by mixing the PHP code and the HTML code. This allows me to generate actual HTML tags dynamically.

在 ASP.NET 中,我还没有找到复制此功能的方法.

In ASP.NET, I haven't found a way to replicate this functionality.

我想过在后面的代码中使用循环,比如 Init() 函数来创建一个 new() 对象数组,设置它们的属性并希望它被传递到 aspx 文件中,但它没有'不工作.

I've thought about using a loop in the code behind on something like the Init() function to create an array of new() objects, setting their attributes and hoping it is passed into the aspx file, but it didn't work.

我该怎么做?

推荐答案

如果要动态创建 ASP.Net 超链接控件你可以简单地这样做:

If you want to creat Dynamically ASP.Net Hyperlink control You can simply do this:

HyperLink hyp = new HyperLink();
    hyp.ID = "hypABD";
    hyp.NavigateUrl = "";
    Page.Controls.Add(hyp);

这篇关于如何在 ASP.NET 中动态创建新的超链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆