c# - jQuery is not finding Asp.net repeater alternating item -


I have a repeater on my webform page, surrounded by a list of it. During compelling the list, I also attach the data-id attribute in tr. The problem is that I need to use that ID in web service call from jQuery, I'm testing whether I have Data-ID Attribute Value I can get an ID by logging in when I click on a button from the repeater item, but I think things, it only logs items and is not optional items

but Not one, three, and five each time I click them, but when I click on the two buttons and buttons, I could not find anything in the console. See the code below

Repeater Template

  & lt; ASP:. Repeater runat = "server" id = "rptList" OnItemDataBound = "rptList_OnItemDataBound" & gt; & Lt; HeaderTemplate & gt; & Lt; Table & gt; & Lt; / HeaderTemplate & gt; & Lt; ItemTemplate & gt; & Lt; Tr runat = "server" id = "trList" & gt; & Lt; Td runat = "server" id = "tdList" & gt; & Lt; / Td> & Lt; Td runat = "server" id = "tdBtnRemove" & gt; & Lt; ASP: button runat = "server" id = "btnRemove" CssClass = "btnRemove" text = "remove" OnClientClick = "return false;" /> & Lt; / TD & gt; & Lt; / TR & gt; & Lt; / ItemTemplate & gt; & Lt; AlternatingItemTemplate & gt; & Lt; Tr runat = "server" id = "trList" & gt; & Lt; Td runat = "server" id = "tdList" & gt; & Lt; / Td> & Lt; Td runat = "server" id = "tdBtnRemove" & gt; & Lt; Asp: button runat = "server" id = "btnRemove" text = "remove" OnClientClick = "return false;" /> & Lt; / Td> & Lt; / TR & gt; & Lt; / AlternatingItemTemplate & gt; & Lt; FooterTemplate & gt; & Lt; / Table & gt; & Lt; / FooterTemplate & gt; & Lt; / ASP: Repeater & gt;  

list item

  list & lt; String & gt; ListObj = New list & lt; String & gt; () {"one two three four five"}; Protected void rptList_OnItemDataBound (object sender, RepeaterItemEventArgs e) {string listItem = (string) e.Item.DataItem; If (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {HtmlTableRow trList = (HtmlTableRow) e.Item.FindControl ( "trList"); TrList.Attributes.Add ("Data-ID", List Items); HtmlTableCell tdList = (HtmlTableCell) e.Item.FindControl ("tdList"); TdList.InnerHtml = listItem; }}  

jQuery button click method:

  $ (".btnRemove"). Click (function () {var dataAttributeVal = $ (this) closest ("tr"); var datA = data attribute data ('id'); console.log (datA);});  

Console Results:

I click on all 5 But I'm logged in only 1, 3 and 5 console

As the comments, your AlternatingItemTemplate miss CssClass = "btnRemove" attribute.

For this reason, your $ (".btnRemove") Clicks (... binding does not target buttons in your AlternatingItemTemplate


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -