1

I've got a Repeater-controller that looks something like this:

<asp:Repeater ID="Postrepeater" runat="server" DataSourceID="datasource" >
<h2>
    <%#Eval("posttitle") %>
</h2>
<p>
    <%#Eval("posttext") %>
</p>
<asp:Button ID="DeleteLinkButton" runat="server" CommandName="Delete" Text="Delete post" />
</asp:Repeater>

The Datasource:

<asp:ObjectDataSource ID="datasource" TypeName="Service" SelectMethod="GetPosts" DataObjectTypeName="Post" runat="server" DeleteMethod="DeletePost" />

And in Service.cs

public List<Posts> GetPosts()
        {
            DALposts dal = new DALposts();
            return dal.GetPosts();
        }

public void DeletePost(Posts post)
    {
        DALPost.DeletePost(post.PostId);
    }

The really wierd thing is that the SelectMethod, GetPosts, works as a charm - just as it should. But when I try to delete the post, the DeleteMethod doesn't call any method - the page just reloads and nothing happens. I've tried to debug the code, but the CommandName="Delete" doesn't call anything at all, and I don't recieve any errors... Any ideas?

Think I posted enough code, but if you think you need more - just tell me so.

Update: After lots of reading and some help here too, I came to the conclusion that this can't be done with a repeater unless I write quite a lot more code - so I canged to a FormView instead. Works like a charm

Marcus Olsson
  • 2,485
  • 19
  • 35

2 Answers2

1

To get something done by setting CommandName u have to implement OnItemCommand check this

Community
  • 1
  • 1
Piotr Auguscik
  • 3,651
  • 1
  • 22
  • 30
1

I dont think that it will be possible the way you have described it here with a repeater. You have to use an gridview instead.

Or you can use the OnItemCommand event on the repeater, check for the Delete argument and then call your delete method.

Bassetassen
  • 20,852
  • 8
  • 39
  • 40