devan
devan

Reputation: 1653

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.

Upvotes: 1

Views: 10261

Answers (2)

Kapil Khandelwal
Kapil Khandelwal

Reputation: 16144

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

Upvotes: 4

Aristos
Aristos

Reputation: 66649

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

Upvotes: 1

Related Questions