Delete an item from an asp:Repeater using jQuery

Gemma Church

How do I delete an item from a asp:Repeater? At the moment I have the following code for the repeater:

<asp:Repeater ID="uxRolesList" runat="server">
    <ItemTemplate>                       
        <div id="<%# GetRolesDivId() %>">
            <asp:TextBox ID="uxTxtBoxRole" runat="server" rows="5" columns="100" Text='<%# Container.DataItem %>' TextMode="multiline" MaxLength="2000"></asp:TextBox>
            <asp:Button ID="uxRemoveRoleBtn" Style="vertical-align:top;" CssClass="remove-roles-btn" runat="server" Text="X" />
            <br />
            <asp:RequiredFieldValidator runat="server" ID="uxValTxtBoxRole" ControlToValidate="uxTxtBoxRole" ErrorMessage="Please complete this role requirement"></asp:RequiredFieldValidator>
            <br /><br />
        </div>
    </ItemTemplate>
</asp:Repeater>     

Which should output something like this:

<div id="roles-1">
    <textarea name="ctl00$mainContent$uxRolesList$ctl01$uxTxtBoxRole" rows="5" cols="100" id="ctl00_mainContent_uxRolesList_ctl01_uxTxtBoxRole">Quick test</textarea>                          <input type="submit" name="ctl00$mainContent$uxRolesList$ctl01$uxRemoveRoleBtn" value="X" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$mainContent$uxRolesList$ctl01$uxRemoveRoleBtn&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="ctl00_mainContent_uxRolesList_ctl01_uxRemoveRoleBtn" class="remove-roles-btn" style="vertical-align:top;" />
    <br />
    <span id="ctl00_mainContent_uxRolesList_ctl01_uxValTxtBoxRole" class="error" style="color:#891F11;display:none;">Please complete this role requirement</span>
    <br /><br />
</div>

And I'm using the following jQuery to 'delete' the item when the delete button is clicked:

$("#roles-" + roleIdNumber).remove();
e.preventDefault();
rolesCounter--;

Where roleIdNumber is 1 in this case.

But when I submit the form, the item still appears - can anyone help me with what is happening?

geevee

i suggest replacing:

<div id="<%# GetRolesDivId() %>">

with:

<div id="<%# GetRolesDivId() %>" class="div_row">

and this line:

<asp:Button ID="uxRemoveRoleBtn" Style="vertical-align:top;" CssClass="remove-roles-btn" runat="server" Text="X" />

with:

<input type="button" style="vertical-align:top;" value="X" class="remove-roles-btn" onclick="$(this).parents('.div_row').remove();rolesCounter--;" />

and remove all the js code you shared here.

hope it helped.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jQuery is not finding Asp.net repeater alternating item

From Dev

How to get/access row value from Repeater using jquery?

From Dev

How to get/access row value from Repeater using jquery?

From Dev

repeater item command in asp.net

From Dev

ASP.NET Converting repeater item to the textbox

From Dev

How to delete item from listView using alertDialog

From Dev

Changing the last datarow from a asp:repeater table if data is shown in asp:label using vb.net

From Dev

how to delete item from list using delete button in react?

From Dev

ASP .NET Using a Repeater inside of UpdatePanel with UpdateProgress

From Dev

Using Bootstrap tabs with ASP NET repeater

From Dev

To bind images in repeater using asp.net

From Dev

Using if-else statment in ASP repeater

From Dev

Add multiple items to a asp repeater using tuples

From Dev

Repeater in asp.net from DB with DropDownList

From Dev

Delete item from db using id from route javascript

From Dev

ASP.NET Repeater Item add divider after each row

From Dev

Remove Item from jQuery autocomplete using Tokenfield

From Dev

Iterate radio button in repeater using jQuery

From Dev

unable to delete row from table using jquery?

From Dev

unable to delete row from table using jquery?

From Dev

Delete item from a list

From Dev

Delete item from object

From Dev

Delete item from SharePoint List using JavaScript and REST

From Dev

Delphi 7 - How to delete an item from listview using its caption

From Dev

Delete item from data-bound JSON list using AngularJs

From Dev

Delete selected item from listbox in windowsphone using c#

From Dev

Unable to delete item from List View using context menu in Android

From Dev

How to delete item from listview using own ArrayAdapter?

From Dev

PHP Delete an Item from the DB using a while loop

Related Related

  1. 1

    jQuery is not finding Asp.net repeater alternating item

  2. 2

    How to get/access row value from Repeater using jquery?

  3. 3

    How to get/access row value from Repeater using jquery?

  4. 4

    repeater item command in asp.net

  5. 5

    ASP.NET Converting repeater item to the textbox

  6. 6

    How to delete item from listView using alertDialog

  7. 7

    Changing the last datarow from a asp:repeater table if data is shown in asp:label using vb.net

  8. 8

    how to delete item from list using delete button in react?

  9. 9

    ASP .NET Using a Repeater inside of UpdatePanel with UpdateProgress

  10. 10

    Using Bootstrap tabs with ASP NET repeater

  11. 11

    To bind images in repeater using asp.net

  12. 12

    Using if-else statment in ASP repeater

  13. 13

    Add multiple items to a asp repeater using tuples

  14. 14

    Repeater in asp.net from DB with DropDownList

  15. 15

    Delete item from db using id from route javascript

  16. 16

    ASP.NET Repeater Item add divider after each row

  17. 17

    Remove Item from jQuery autocomplete using Tokenfield

  18. 18

    Iterate radio button in repeater using jQuery

  19. 19

    unable to delete row from table using jquery?

  20. 20

    unable to delete row from table using jquery?

  21. 21

    Delete item from a list

  22. 22

    Delete item from object

  23. 23

    Delete item from SharePoint List using JavaScript and REST

  24. 24

    Delphi 7 - How to delete an item from listview using its caption

  25. 25

    Delete item from data-bound JSON list using AngularJs

  26. 26

    Delete selected item from listbox in windowsphone using c#

  27. 27

    Unable to delete item from List View using context menu in Android

  28. 28

    How to delete item from listview using own ArrayAdapter?

  29. 29

    PHP Delete an Item from the DB using a while loop

HotTag

Archive