只有第一次删除按钮工作才能删除列表中的产品 [英] only first time remove button work to remove product in my list

查看:66
本文介绍了只有第一次删除按钮工作才能删除列表中的产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BiggestBookWeb.BLHelper;

namespace BiggestBookWeb.Forms
{
    public partial class MyList : System.Web.UI.Page
    {
        DataSet oDS = new DataSet();
        DataTable dt = new DataTable();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
             
                int counta = Convert.ToInt32(Session["AddToListCount"]);
                for (int i = 0; i <= counta; i++)
                {
                    string keyword = Convert.ToString(Session["AddToList" + i]);

                    oDS = SearchHelper.getCompareResultByKeywords(keyword);
                    if (i == 0)
                    {
                        foreach (DataColumn col in oDS.Tables[0].Columns)
                        {
                            dt.Columns.Add(col.ColumnName, col.DataType);
                        }
                    }
                    if (keyword != "")
                    {
                        dt = tblGridRow();
                    }
                }
                GridView1.DataSource = dt;
                GridView1.DataBind();

            }
        }




        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {




            if (e.CommandName == "Remove")
            {
                int count = Convert.ToInt32(Session["AddToListCount"]);
                for (int i = 0; i <= count; i++)
                {
                    Session["AddToList"] = "";
                    Response.Redirect("../Forms/MyList.aspx");
                }
            }
        }
        
        public DataTable tblGridRow()
        {
            
            for (int i = 0; i < 1; i++)
            {
                DataRow dr = dt.NewRow();
                dr["LG_ITEM_DSC"] = oDS.Tables[0].Rows[0]["LG_ITEM_DSC"].ToString();
                dr["MFR_SKU_NUM"] = oDS.Tables[0].Rows[0]["MFR_SKU_NUM"].ToString();
                string Price = oDS.Tables[0].Rows[0]["LIST_AMT"].ToString();
                int length = Price.Length;
                dr["LIST_AMT"] = Price.Remove(length - 2, 2);
                dr["BRND_LOGO"] = oDS.Tables[0].Rows[0]["BRND_LOGO"].ToString();
                dr["INV_UN_CDE"] = oDS.Tables[0].Rows[0]["INV_UN_CDE"].ToString();
                dt.Rows.Add(dr);
            }
            return dt;
        }


        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            GridView1.DataSource = dt;

            GridView1.DataBind();

            

        }
     }
}

推荐答案

HI,



如果页面是MyList.aspx页面,那么您不需要一次又一次地重定向页面。只需确保网格绑定在一个单独的函数中并调用函数/绑定网格代替



If the page is MyList.aspx page then you need not to redirect the page again and again. Just make sure the grid binding in a separate function and call the function/bind the grid in place of
Response.Redirect("../Forms/MyList.aspx");



这将解决您的问题。







如果你想从网格中删除一行,请使用以下代码。




This will resolve your problem.



If you want to delete a row from the grid then use the following code.

if (e.CommandName == "Delete")
    {
        int index = Convert.ToInt32(e.CommandArgument);
        GridView1.DeleteRow(index);
        ((DataTable)ViewState["DataTable"]).Rows[index].Delete();
        ((DataTable)ViewState["DataTable"]).AcceptChanges();
        GridView1.DataSource = (DataTable)ViewState["Data"];
        GridView1.DataBind();
    }





通过这种方式你可以删除一行。



[/编辑]





谢谢



In this way you can delete a single row.

[/Edit]


Thanks


这篇关于只有第一次删除按钮工作才能删除列表中的产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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