我想在Asp.net页面动态制作链接。
这是我的aspx代码:
<a href='<%# String.Format("LeadInformation.aspx?refNo={0}&imgpath={1}",refno[0],imgpath[0]) %>'>
Aspx.cs代码:
public String[] imgpath = new string[8];
public String[] refno = new String[8];
protected void Page_Load(object sender, EventArgs e){
imgpath[0] ="some path";
refno[0] = "some refno";
....
}
这种方式对我不起作用。请帮我分配refNo = {0}&amp; imgpath = {1}来创建链接。谢谢。
答案 0 :(得分:4)
在.aspx文件中:
<a runat="server" id="link1"></a>
在您的代码中:
protected void Page_Load(object sender, EventArgs e){
imgpath[0] ="some path";
refno[0] = "some refno";
link1.HRef = String.Format("LeadInformation.aspx?refNo={0}&imgpath={1}",refno[0],imgpath[0]);
link1.InnerHtml = "My link";
}
答案 1 :(得分:1)
如果我在此处了解此问题,您只需将<%#
更改为<%=
并初始化更正数组字符串的表。
protected void Page_Load(object sender, EventArgs e){
imgpath[0] ="some path";
refno[0] = "some refno";
}