Take the 2-minute tour ×

I've done this with a asp.net Gridview. but does anybody have any examples on how to pass row information from an asp.net button in SharePoint Dataview rows to an inline C# function?

the button Repeats as follows:

<asp:Button runat="server" Text="Delete" id="Delete{@ID}"  OnClick="DeleteDoc()"/>

My function looks like this:

void DeleteDoc(object sender, EventArgs e) { }


I tried adding another parameter but get:

No overload for 'DeleteDoc' matches delegate 'System.EventHandler'

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Try to change your method access modifier to protected and OnClick="DeleteDoc()" to OnClick="DeleteDoc".

Also i didn't managed to make it work with id="Delete{@ID}" so try without that to.

This worked on my test case

 <asp:Button runat="server" Text="Delete"  


   protected void DeleteDoc(object sender, EventArgs e)
            Button b = sender as Button;            
share|improve this answer
I'm sure your answer is correct and right on. I coded it up as such, but now realize that for some reason, my onclick handler is never getting called. I'm developing this through sharepoint designer, so tough to troubleshot. <asp:Button runat="server" Text="Delete" id="Delete{@ID}" CommandArgument="{@FileRef}" OnClick="DeleteDoc"/> in the markup. the button repeats for every row. and my handler is this void DeleteDoc(object sender, EventArgs e) { sendmail("DeleteDoc"); Button b = sender as Button; string FileRef = b.CommandArgument; If place the button outside of the DataView it works. –  cyberpine Sep 14 '10 at 21:14
Are you testing in a SharePoint DataView or asp.net GridView? If I remove the {@ID} I get duplicate control errors as expected. Someone suggested I can't add a button to a DataView row and that I must use an form Action. Finding very little information on Dataview Custom Row actions. As mentioned, but the button works when I pull it out of the Dataview. Thanks again. –  cyberpine Sep 15 '10 at 10:37
I used plain asp Repeater. I didn't know that you are using SP Designer. For testing i made simple web part that loads user control. All my code is in user control. Can you pleas post code that include DataView. –  boro.djuka Sep 15 '10 at 12:12
Here the issue a little further into the solution. I have a Dataview bound to Doc lib. I select Editing and add an insert item link. Seperate issue, but that link does not upload where I want and I see no way to configure it without re-writng the control. So I add (my working) button right there in the middle of DataView XSL. Again, I click on the new button and nothing happens, while the same button on the outside works fine. If I could configure what folder to upload to in the Lib I'd be done. Code in next comment. –  cyberpine Sep 16 '10 at 16:46
<a href="javascript: {ddwrt:GenFireServerEvent('__cancel;dvt_1_form_insertmode={1}')}">Upload File</a> <asp:Button runat="server" Text="Upload New Document" id="UploadDocsI" OnClick="UploadDoc"/> </td> –  cyberpine Sep 16 '10 at 16:46
add comment

Your Answer


