Reputation: 2527
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
Upvotes: 1
Views: 1210
Reputation: 21814
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.
Upvotes: 1
Reputation: 3681
To get something done by setting CommandName
u have to implement OnItemCommand
check this
Upvotes: 1