How do you set href attribute of anchor tag that is within a repeater in code behind?

后端 未结 4 1482
庸人自扰
庸人自扰 2021-01-25 06:23

normally on would use the following :-

aspx page:-

Link1 

code behind:-

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-25 07:12

    For example, in the ItemDatabound event:

    protected void rptData_ItemDataBound(object source, RepeaterCommandEventArgs e)
    {
        HtmlAnchor a1 = (HtmlAnchor)e.Item.FindControl("a1");
        a1.HRef = "www.mySite.com/mypage.aspx";
    }
    

    Also, don't forget to put runat="server" on that anchor

    Link1 
    

提交回复
热议问题