Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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);
}
Posted
Updated 25-Jul-11 22:58pm
v3

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(); 
 
Share this answer
 
Comments
Shibiny 26-Jul-11 4:42am    
Thanks For ur Help

But a Error occured

The Update method can only be called on UpdatePanel with ID 'UpdatePanel2' when UpdateMode is set to Conditional.


Now 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);




Display();//Bind the data source To ListView
UpdatePanel2.Update();

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



}

Display();

UpdatePanel2.Update();
break;
}
}

}


}
Shahriar Iqbal Chowdhury/Galib 26-Jul-11 6:35am    
navigate to *.aspx and set UpdateMode="Conditional" to UpdatePanel2
Shibiny 26-Jul-11 7:38am    
I Try Thhis now there is no error but still listview is not updating.pls help me
Shibiny 4-Aug-11 1:41am    
i still have this same problem in some pages of same application .pls help me
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.
 
Share this answer
 
Comments
Shibiny 26-Jul-11 5:32am    
Sorry My problem is when Deleting An Item From Listview The Listview is not updated.But the listview is updating When use response.redirect instead of Display(), but Display() function is working after delete
dhawaljoshi 26-Jul-11 5:42am    
ya then if u have used display function then i guess it is being misplaced by u ....if after deleting in any case display is called than data will be displayed.
Shibiny 26-Jul-11 6:02am    
Yes, I use Display() after Delete
Shibiny 26-Jul-11 6:56am    
In Display() Function Have CurrectDatas in Dataset And Bind That Data toListView .But When Display The ListView Show Old Datas.But when We Use Response.redirect NO Problem.And In Save I Use The Same Display() ,that is Workig

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900