简体   繁体   中英

Make a dynamic Link in Asp.net page

I want to make a Link dynamically in Asp.net page.

here is my aspx code:

  <a href='<%# String.Format("LeadInformation.aspx?refNo={0}&imgpath={1}",refno[0],imgpath[0]) %>'>

Aspx.cs code:

    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";
....
}

This way is not working for me. please help me to assign refNo={0}&imgpath={1} to create the link. Thank you.

In your .aspx file:

<a runat="server" id="link1"></a>

In your code:

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";
}

If I understand the issue here you only need to change the <%# to <%=

and initialize correct the tables of array strings.

protected void Page_Load(object sender, EventArgs e){
    imgpath[0] ="some path";
    refno[0]  = "some refno";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM