理解ASP.NET动态数据支架的删除链接 [英] Understanding the delete link in ASP.NET Dynamic Data scaffolds

查看:160
本文介绍了理解ASP.NET动态数据支架的删除链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于ASP.NET动态数据Web页的自动脚手架做了大部分的我需要它,我想用它作为基础这个项目做的事情。

Since the automatic scaffolding 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.

这是在自动生成的code定义为

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?");'/>

到底发生了什么吗?有没有在code的地方命名为删除(如在CommandName属性使用)的方法?什么参数传递呢?和:我将如何调用自定义的方法

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?

我试着用调试器单步运行它,但它是容易松动自己在LINQ数据类,所以我什么也没找到。

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

在此先感谢!

推荐答案

该删除的CommandName通常是数据源标记下的联系,等效DeleteCommand会在同一页上,例如:

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...

您可以通过数据源控件属性配置delete命令,或通过网页。

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

至于新的命令,通常的方式是增加一个新的LinkBut​​ton,改变命令名字的东西,是有道理的,你想要做什么的CommandName =EmailNotice

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".

然后通过评估eventargs.CommandName(e.CommandName)赶在{} YourDataTableName单击此按钮的CommandName _ItemCommand事件,这是概而言之,因为我不知道你的自定义数据表是由。当e.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.

编辑: Linq的是一个有点不同!您可以参考这个MSDN文章,更主要的是使用 GetCommand 方法

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

这篇关于理解ASP.NET动态数据支架的删除链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆