【发布时间】:2013-03-27 10:49:57
【问题描述】:
我有一个数据绑定到网格视图的对象列表。 gridview 有一个附加到行的删除按钮。
我需要通过点击保持对象列表(就像离线工作一样) 我不想使用会话、cookie 或视图状态
当前行为: 列表有 4 项 => 删除 1 项 => 列表有 3 项 => 删除 1 项(POSTBACK)列表重新生成 4 项然后删除 1。
class Emails
{
public string Email { get; set; }
public Emails(string _Address)
{
Email = _Address;
}
}
if (!IsPostBack)
{
ListOfEmails = new List<Emails>();
ListOfEmails.Add(new Emails("1@a.com"));
ListOfEmails.Add(new Emails("2@a.com"));
ListOfEmails.Add(new Emails("3@a.com"));
ListOfEmails.Add(new Emails("4@a.com"));
GridView1.DataSource = ListOfEmails;
GridView1.DataBind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string EmailToBeDeleted = GridView1.Rows[e.RowIndex].Cells[0].Text;
ListOfEmails.Remove(ListOfEmails.Find(L => L.Email == EmailToBeDeleted));
GridView1.DataSource = null;
GridView1.DataSource = ListOfEmails;
GridView1.DataBind();
}
aspx:
<asp:BoundField DataField="Email" HeaderText="Email Address" />
<asp:ButtonField ButtonType="Button" CommandName="Delete" HeaderText="Action2"
ShowHeader="True" Text="Delete" />
<asp:CommandField ButtonType="Image" DeleteImageUrl="~/delete.gif"
ShowDeleteButton="True" />
“我现在有 2 个删除按钮”
【问题讨论】:
-
将它们放在更新面板中?
-
这只会抑制回发或使它们不可见我希望禁用它们,直到我明确命令回发。