删除后不会更新ListView [英] ListView is not updated after delete

查看:92
本文介绍了删除后不会更新ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在asp.net应用程序中,我有一个问题,从列表视图中删除一行后,列表视图未更新,列表视图位于updatepanel中,但是没有任何问题.

我的代码是
受保护的void lstExchangeHistoryView_ItemCommand(对象发送者,ListViewCommandEventArgs e)
{

如果(e.Item.ItemType == ListViewItemType.DataItem)
{
标签lblRateHistoryID =(Label)e.Item.FindControl("lblRateHistoryID");



int _RateHistoryID = Convert.ToInt32(lblRateHistoryID.Text);
开关(e.CommandName)
{

案例删除":
{
_OperationMode =删除";
ExchangeHistory objExchangeHistory =新的ExchangeHistory();
if(_RateHistoryID!= 0)
{
objExchangeHistory.Delete(_RateHistoryID);




}
其他
{
ListViewDataItem dataItem =(ListViewDataItem)e.Item;
lstExchangeHistoryView.Items.Remove(dataItem);



}

Display();

UpdatePanel2.Update();
休息;
}
}

}

//btnRetrieve_Click(null,null);
}

In asp.net Application I Have a problem, after deleting a row from listview the listview is not updated ,the listview is in updatepanel,but in saving no problem.

My code is
protected void lstExchangeHistoryView_ItemCommand(object sender, ListViewCommandEventArgs e)
{

if (e.Item.ItemType == ListViewItemType.DataItem)
{
Label lblRateHistoryID = (Label)e.Item.FindControl("lblRateHistoryID");



int _RateHistoryID = Convert.ToInt32(lblRateHistoryID.Text);
switch (e.CommandName)
{

case "Delete":
{
_OperationMode = "Delete";
ExchangeHistory objExchangeHistory = new ExchangeHistory();
if(_RateHistoryID!=0)
{
objExchangeHistory.Delete(_RateHistoryID);




}
else
{
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
lstExchangeHistoryView.Items.Remove(dataItem);



}

Display();

UpdatePanel2.Update();
break;
}
}

}

// btnRetrieve_Click(null, null);
}

推荐答案



您必须再次Bind 数据源,并且在删除后必须更新UpdatePanel,如果您的UpdatePanel ID是UpdatePanel1 而不是

Hi,

You have to Bind the data source again and you have to update the UpdatePanel after delete, If your UpdatePanel ID is UpdatePanel1 than,

//code for delete a row from listview
lstExchangeHistoryView.Datasource=YOUR_DATA_SOURCE;
lstExchangeHistoryView.DataBind();
UpdatePanel.Update(); 


listView1.Items.RemoveAt(0);

尝试执行此操作,因为在使用listview时无需使用listView1.refresh();.没有任何意义,因为添加或删除它会自动更新列表框.
listView1.Items.RemoveAt(0);

try doing this because when you are using listview no need to use listView1.refresh(); has no meaning as on adding or deleting it automatically updates the listbox.


这篇关于删除后不会更新ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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