| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1272 人关注过本帖
标题:gridview数据绑定问题
只看楼主 加入收藏
tokoyoshi
Rank: 2
等 级:论坛游民
帖 子:99
专家分:67
注 册:2009-10-24
结帖率:87.1%
收藏
已结贴  问题点数:10 回复次数:1 
gridview数据绑定问题
问题:
gridview绑定数据,模板列定义删除功能,当删除完最后一行数据时,gridview始终显示最后一个,无论删除多少次都是一样,望高手解释,谢谢。
代码:
 public List<int> list= new List<int>();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {

                    bind();

            }

        }

        private void bind()
        {
            if (null != Session["listid"])
            {
                list = (List<int>)Session["listid"];
                if (list.Count > 0)
                {
                    List<ProductInfo> listinfo = new List<ProductInfo>();
                    foreach (int item in list)
                    {
                        ProductInfo pro = ProductBLL.GetProductById(item);
                        listinfo.Add(pro);
                    }
                    this.GridView1.DataSource = listinfo;
                    this.GridView1.DataBind();
               
                }
                else
                {
                    this.la1.Text = "您的收藏夹中无任何车型!";
                    this.div2.Visible = true;
                    this.div3.Visible = false;
                    this.divGrid.Visible = false;
                }



            }


        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if ( == "Delete")
            {
                int id = int.Parse(());
                list = (List<int>)Session["listid"];
                foreach (int item in list)
                {
                    if (id == item)
                    {
                        list.Remove(item);
                        Session["listid"] = list;
                        break;
                    }
                }
                bind();
            }
        }
搜索更多相关主题的帖子: 数据 gridview 绑定 
2010-01-08 16:32
zhangwc
Rank: 2
等 级:论坛游民
帖 子:49
专家分:67
注 册:2008-6-11
收藏
得分:10 
foreach (int item in list)
                {
                    if (id == item)
                    {
                        list.Remove(item);
                        break;
                    }
                }
        Session["listid"] = list;
                bind();
2010-01-08 17:18
快速回复:gridview数据绑定问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049324 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved