1.11M Members

adding link to a repeater

 
-1
 

in html

<div id="dvEmpName" class="w200s">
                                <a href="#" id="basic" runat="server"><%# Eval("suppname")%></a></div>

here href id is basic which is used for the java script function

so in code add repeater itemdatabound event  


  protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            RepeaterItem rowItem = e.Item;

            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                HtmlControl btn = e.Item.FindControl("basic") as HtmlControl;
                HtmlControl rowContainer = e.Item.FindControl("dvRowData") as HtmlControl;

                if (btn != null)
                {
                    btn.Attributes.Add("onClick", string.Format("showDataRow('{0}');", rowContainer.ClientID));
                }
            }
        }
 
0
 

Please refrain from putting JavaScript in your code behind. If you want to bind a JavaScript event to an element, do it in JavaScript.

Keep JavaScript separate from your page (keep in an external file)
Keep CSS separate (no inline styles, keep in external file)
HTML pages should only have HTML with references to the other resources need (js and css files).

This will also make it easier to debug later on.

Also instead of using HTMLControls, you might find it easier to use the server controls instead.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article