嘿伙计们,我想知道如何删除已插入列表视图的项目
实际上已经在网上搜索了一段时间,找不到有用的东西。
这是我的代码,我希望能够删除我通过列表添加的内容,谢谢。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<Book> list = (List<Book>)Session["SelectedBooks"];
if (list != null)
{
GridViewProducts.DataSource = list;
GridViewProducts.DataBind();
}
//list of borrows
}
}
protected void GridViewProducts_RowCommand(object sender,
GridViewCommandEventArgs e)
{
try
{
if (e.CommandName == "Remove")
{
GridViewProducts.DeleteRow(GridViewProducts.SelectedIndex);
}
}
catch (Exception)
{
lblInfo.Text = "Can not remove selected book from Bag.";
}
}