English 中文(简体)
删除一行的参数
原标题:Parameter for deleting a row

I have a problem with my delete parameter. I am using a GridView and a ObjectDataSource. And I would like to delete one row. But when I debug is see that the value of CustomerId is always 0 in my Business Logic Layer.

我的法典

我有两个删除参数:Id。 这些名字与我的《维也纳条约法公约》中的名称相同。

<asp:GridView DataKeyNames="Id" ID="gvFavoriteMovies" DataSourceID="odsFavoriteMovies" AutoGenerateColumns="False" 
    runat="server">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>            
                    <asp:Label ID="lblTitel" runat="server" Text= <%# DataBinder.Eval(Container.DataItem, "Title")%> ></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>

        <asp:CommandField ShowDeleteButton="True" />

    </Columns>
</asp:GridView>

<asp:ObjectDataSource ID="odsFavoriteFilm" runat="server"
TypeName="MovieMonstrDataLayer.bll.BLLMovies"
SelectMethod="GetFavoriteMoviesFromUser"
DeleteMethod="DeleteFavoriteMoviesFromUser" 
onobjectcreating="odsFavoriteFilm_ObjectCreating" 
    ondeleting="odsFavoriteFilm_Deleting">
    <DeleteParameters>
        <asp:Parameter Name="Id" DbType="Int32" Direction="Input" />
        <asp:Parameter Name="CustomerId" DbType="Int32" Direction="Input" />
    </DeleteParameters>
    <SelectParameters>
        <asp:Parameter DbType="Int32" Direction="Input" Name="CustomerId" />
    </SelectParameters>
</asp:ObjectDataSource>

这在档案背后的法典中。

在删除行文时,我把贴在客户中的标记的价值分配给删除参数<条码>。 所有这一切都奏效。 我请删除参数。

protected void odsFavoriteFilm_Deleting(object sender, ObjectDataSourceMethodEventArgs e)
{
        if (Context.User.Identity.IsAuthenticated)
        {
            this.odsFavoriteFilm.DeleteParameters["CustomerId"].DefaultValue = ((MovieMonstrIdentity)Context.User.Identity).Customer.Id.ToString();
            this.odsFavoriteFilm.DataBind();
        }
    }

通常,在我的商业界,我现在要获得正确的<条码>。 0. 虽然没有计票员。

public int DeleteFavoriteFilmFromUser(int Id, int CustomerId)
    {
        try
        {
            return Adapter.DeleteFavoriteFilmFromUser(Id, CustomerId);
        }

        catch (Exception ex)
        {
            throw ex;
        }
    }

What am I doing wrong?

最佳回答

包括<条码>CustomerID,载于<条码>。

<asp:GridView DataKeyNames="Id,CustomerId" ...>

更新之前是否这样做

protected odsFavoriteFilm_DataBinding(object sender, EventArgs e) {
    if(!IsPostBack) {
        this.odsFavoriteFilm.DeleteParameters["CustomerId"].DefaultValue = ((MovieMonstrIdentity)Context.User.Identity).Customer.Id.ToString();
    }
}

或确定指挥的实际参数价值

protected void odsFavoriteFilm_Deleting(object sender, ObjectDataSourceMethodEventArgs e) {
    if (Context.User.Identity.IsAuthenticated) {
        e.Command.Parameters["CustomerId"].Value = ((MovieMonstrIdentity)Context.User.Identity).Customer.Id.ToString();
    }
}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签