views:

103

answers:

1

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'

+1  A: 

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"  
             OnClick="DeleteDoc" 
             CommandArgument='<%# Eval("ID")%>'/>

and

   protected void DeleteDoc(object sender, EventArgs e)
        {
            Button b = sender as Button;            
            YourDeleteDocumentHelperMethod(b.CommandArgument);
        }
boro.djuka
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
@boro, 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
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
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
<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