从行gridview行减少数量。 ASP.Net [英] Reduce Quantity from row gridview row. ASP.Net

查看:74
本文介绍了从行gridview行减少数量。 ASP.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我有一个带有模板字段中按钮的网格。我希望此按钮从SQL中删除但无法使其正常工作。只收到错误消息。这是我的代码。



Hi I have a gridrow with a button in a template field. I want this button to delete from SQL but cannot get it working. Only getting error messages. Here is my code.

<asp:GridView ID="gvBasket" runat="server" AutoGenerateColumns="False">
     <Columns>
            <asp:BoundField DataField="ProductName" HeaderText="Product Name" SortExpression="ProductName" />
            <asp:BoundField DataField="qty" HeaderText="Quantity" SortExpression="qty" />
            <asp:BoundField DataField="UnitPrice" HeaderText="Unit Prce" SortExpression="unitPrice"

                HtmlEncode="false" DataFormatString="{0:c}" />
            <asp:TemplateField HeaderText="Total" SortExpression="Total">
                <ItemTemplate>
                    <asp:Label ID="lblTotal" runat="server" Text='<%# Eval("Total", "{0:c}") %>'  />
                </ItemTemplate>
                <FooterTemplate>
                <asp:Label ID="lblsubTotal" runat="server" />

                </FooterTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="sessionID" HeaderText="Session" 

                SortExpression="sessionID" visible="false"/>
            <asp:BoundField DataField="UserID" HeaderText="user" SortExpression="UserID" Visible="false" />
            <asp:BoundField DataField="ProductID" HeaderText="ProductID" 

                SortExpression="ProductID" visible="false"/>
            <asp:TemplateField HeaderText="Edit">
                <ItemTemplate>
                    <asp:Button ID="Delete" runat="server" 

                        CommandArgument='<%# Bind("productID") %>' onclick="Delete_Click" 

                        Text="Delete" CommandName="DeleteItem" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <FooterStyle BackColor="#003399" />
    </asp:GridView>





我的代码背后是



my code behind is

protected void Delete_Click(object sender, EventArgs e)
   {
       if (!Page.IsPostBack)
       {

           Button btn = (Button)sender;
           int id = int.Parse(btn.CommandArgument);

           string Query = "DELETE FROM ShoppingBasket WHERE Date IN (SELECT TOP 1 Date FROM shoppingBasket WHERE  ProductID = " + id + " AND UserID = '" + (string)Session["UserName"] + "' ORDER BY Date DESC)";

           ConnectionHandler objHandler = new ConnectionHandler();
           DataTable dt = objHandler.ExecuteSelect(Query);
       }


   }





错误信息是:



无效的回发或回调参数。使用< pages enableeventvalidation =true>启用事件验证在配置或<%@ Page EnableEventValidation =true%>在一个页面中。出于安全考虑,此功能可验证回发或回调事件的参数是否来自最初呈现它们的服务器控件。如果数据有效且符合预期,请使用ClientScriptManager.RegisterForEventValidation方法注册回发或回调数据以进行验证。



描述:期间发生了未处理的异常执行当前的Web请求。请查看堆栈跟踪以获取有关错误及其源自代码的更多信息。



the error message is:

Invalid postback or callback argument. Event validation is enabled using <pages enableeventvalidation="true"> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

推荐答案

在您的aspx页面中将其设为false ..

make it false in your aspx page..
Page EnableEventValidation="false"


这篇关于从行gridview行减少数量。 ASP.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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