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();
}
}