开发者

Understanding the delete link in ASP.NET Dynamic Data scaffolds

开发者 https://www.devze.com 2022-12-21 20:24 出处:网络
Since the automatic sc开发者_运维百科affolding of ASP.NET Dynamic Data Web Pages does most of the things I need to do for this project on its on, I\'d like to use it as a basis.

Since the automatic sc开发者_运维百科affolding of ASP.NET Dynamic Data Web Pages does most of the things I need to do for this project on its on, I'd like to use it as a basis.

Now, I like to add another link to the "Edit" "Delete" "Details" trio on my custom table view. I'd like it behave much like the "Delete" button, i.e. not call another page, but do something in the background (Here: Send an email.) and then refresh the view. Alas, I fail to understand how this "Delete" link works.

It is defined in the automatically generated code as

<asp:LinkButton ID="DeleteLinkButton" 
     runat="server" CommandName="Delete"
     CausesValidation="false" Text="Delete"
     OnClientClick='return confirm("Are you sure you want to delete this item?");'/>

What exactly happens here? Is there a method in the code somewhere named "Delete" (like used in the CommandName property)? What arguments are passed there? And: How would I call a custom method?

I tried stepping through it using the debugger, but it is easy to loose oneself in the LINQ Dataclasses, so I found nothing.

Thanks in advance!


The Delete CommandName is normally ties to an equivalent DeleteCommand on the same page under the datasource tag, for example:

 <asp:SqlDataSource ID="SqlDataSourcePending" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionStringPending %>" 
        DeleteCommand="DELETE FROM [CSNTable] WHERE [ID] = @ID" 
        InsertCommand="INSERT INTO [CSNTable] ([CSNDate], [CSNStatus], [CSNAuthor], [CSNSubject], [CSNMessage]) VALUES (@CSNDate, @CSNStatus, @CSNAuthor, @CSNSubject, @CSNMessage)" 
        SelectCommand="SELECT ID, CSNDate, CSNStatus, CSNAuthor, CSNSubject, CSNMessage FROM CSNTable WHERE (CSNStatus LIKE 'Pending')" 
        UpdateCommand="UPDATE [CSNTable] SET [CSNDate] = @CSNDate, [CSNStatus] = @CSNStatus, [CSNAuthor] = @CSNAuthor, [CSNSubject] = @CSNSubject, [CSNMessage] = @CSNMessage WHERE [ID] = @ID">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int16" />
        </DeleteParameters>
        <UpdateParameters>
            .........etc...

You can configure the delete command via the datasource control property, or via the page.

As far as a new command, the usual way is to add a new linkbutton, change the command name to something that makes sense for what you want to do CommandName="EmailNotice".

Then catch this button click commandname in the {YourDataTableName}_ItemCommand event by evaluating the eventargs.CommandName (e.CommandName), this is speaking very generally since I do not know what your custom data table is comprised of. When the e.CommandName=="EmailNotice", then you do what you need.

EDIT: Linq is a little different! You can refer to this MSDN article, but the main thing is using the GetCommand method

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号