1

当我想阅读 e.CommandArgument 时,我收到错误消息“输入字符串的格式不正确。”。我的标记部分如下所示:

<asp:GridView ID="GridViewAllProducts" runat="server" 
    AutoGenerateColumns="False" GridLines="None"
             AllowPaging="True" Width="100%"
             EmptyDataText="هیچ محصولی پیدا نشد" 
            onrowcommand="GridViewAllProducts_RowCommand" 
    onrowdeleting="GridViewAllProducts_RowDeleting"
    OnPageIndexChanging="GridViewAllProducts_PageIndexChanging">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <div class='rowTableDiv rowAllNewsUC'>
                            <asp:HiddenField ID="hiddenId" runat="server" Value='<%# Bind("Id") %>' />
                            <img id="imgImage" src='<%# Bind("Image") %>' class="imgNewsAllNewsUC noBorder" alt="" runat="server" />
                            عنوان محصول:&nbsp;<asp:Label ID="lblTitle" runat="server" Text='<%# Bind("Title") %>'></asp:Label><br />
                            گروه:&nbsp;<asp:Label ID="lblCategory" runat="server" Text='<%# ProductC.GetProductCategoryName(Convert.ToInt32(Eval("CategoryId"))) %>'></asp:Label><br />
                            کد:&nbsp;<asp:Label ID="lblCode" runat="server" Text='<%# Bind("Code") %>'></asp:Label><br />
                            ابعاد:&nbsp;<asp:Label ID="lblDimention" runat="server" Text='<%# Bind("Dimention") %>'></asp:Label><br />
                            تعداد رنگ:&nbsp;<asp:Label ID="lblNumberOfColors" runat="server" Text='<%# Bind("NumberOfColors") %>'></asp:Label><br />
                            قیمت:&nbsp;<asp:Label ID="lblPrice" runat="server" Text='<%# nmsPublicClass.PublicClassC.ThousandSeparator(Convert.ToDecimal(Eval("Price"))) %>'></asp:Label>
                            <asp:LoginView ID="LoginView1" runat="server">
                                <RoleGroups>
                                    <asp:RoleGroup Roles="Administrator">
                                        <ContentTemplate>
                                            <div class='rowTableDiv rowInfoAllNewsUC'>
                                                <asp:Panel ID="pnlEdit" CssClass='colTableDiv' runat="server">
                                                    <div class='colTableDiv colInfoAllNewsUC'>
                                                        <asp:LinkButton ID="lbEdit" 
                                                            CommandArgument='<%# Bind("Id") %>' 
                                                            PostBackUrl='<%# String.Format("~/Page/Admin/InsertProduct.aspx?Mode=Edit&Id={0}", Eval("Id"))%>' 
                                                            Font-Underline="false" 
                                                            CommandName="edit" 
                                                            runat="server">
                                                            <img id='img2' class='noBorder imgEditAllNewsUC' src="../../image/note_edit.png" alt="ویرایش" />
                                                        ویراش</asp:LinkButton>
                                                         <asp:LinkButton ID="lbDelete" CommandArgument='<%# Bind("Id") %>' Font-Underline="false" CommandName="delete" runat="server">
                                                            <img id='img1' class='noBorder imgEditAllNewsUC' src="../../image/delete.png" alt="حذف" />
                                                        حذف</asp:LinkButton>
                                                    </div>
                                                </asp:Panel>
                                            </div>
                                        </ContentTemplate>
                                    </asp:RoleGroup>
                                </RoleGroups>
                            </asp:LoginView>
                            <div class="divHidden">
                                <asp:Label ID="lblID" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
                            </div>
                        </div>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <EmptyDataRowStyle CssClass="lblError" />
            <PagerStyle CssClass="pagerGridView" />
        </asp:GridView>

我背后的代码如下:

protected void GridViewAllProducts_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "delete")
    {
        int productId = Convert.ToInt32(e.CommandArgument);

        string image = new ProductC().GetProductBy_Id(productId).Image;

        Result r = new ProductC().DeleteBy_Id(productId);
        if (r.IsSuccess)
        {
            File.Delete(Server.MapPath(image));
        }

        GridViewAllProducts.DataSource = new ProductC().GetAllProducts();
        GridViewAllProducts.DataBind();
    }
}

我在以下行收到错误“输入字符串的格式不正确。 ”:

int productId = Convert.ToInt32(e.CommandArgument);

问题是什么。请帮我。谢谢你。

4

0 回答 0