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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.