0

Hello I had problem

I want to delete row from my datatable through asp:linkbutton. How can I do this. I had the following code, but it adds another row to the table

protected void delCart(object s, DataTableNewRowEventArgs e)
{
dt = (DataTable)Session["Cart"];
dt.Rows[e.Item.ItemIndex].Delete();
//dt.Rows(e.Item.ItemIndex).Delete();


int CartItem = (int)Session["cartItem"];
CartItem = CartItem - 1;
Session["cartItem"] = CartItem;
Session["Cart"] = dt;
DataList1.DataSource = dt;
DataList1.DataBind();



updateCart();
Response.Redirect("ShoppingCart.aspx");


}

The updateCart() just updates the cart values.

Edited by happygeek: fixed formatting

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by zezo
0

At first type your code on DeleteCommand event ,choose it from event properties

private void DataList1_DeleteCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
		{
		
		}

Try the links below , it contains sample codes that help you:
http://authors.aspalliance.com/aspxtreme/webforms/controls/allowinguserstodeleteitemsindatalist.aspx
http://www.dotnetjunkies.ddj.com/Article/6614EF8F-2ADB-4AEB-B2B7-D96278B53D74.dcik
http://www.ondotnet.com/pub/a/dotnet/2003/03/10/datalist.html

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.