1,105,226 Community Members

adding link to a repeater

weblion
Newbie Poster
19 posts since Feb 2012
Reputation Points: -11 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Banned
 
-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));
                }
            }
        }
Member Avatar
stbuchok
Posting Shark
957 posts since May 2011
Reputation Points: 123 [?]
Q&As Helped to Solve: 142 [?]
Skill Endorsements: 2 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article