0

Hi! I am using a Datatable to maintain a shopping cart. In the gridview I have a textbox for quantity and I want that when the user changes the quantity, the subtotal field changes accordingly, and the datatable also gets updated accordingly. But my textChanged event is not firing at all. Please help!!!! Here's the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
            if (Session["Cart"] == null)
            {
                lblDisp.Text = "You Have No Items in Cart Right Now!!!!";
            }
            else
            {
                DataTable mydt = new DataTable();
                mydt = (DataTable)Session["Cart"];
                GVCart.DataSource = mydt;
                GVCart.DataBind();
            }

    }

    protected void GVCart_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        DataTable dt = (DataTable)Session["Cart"];
        GridViewRow row = (GridViewRow)GVCart.Rows[e.RowIndex];
        string PId = GVCart.Rows[e.RowIndex].Cells[0].Text;
        for (int i = dt.Rows.Count - 1; i >= 0; i--)
        {
            DataRow dr = dt.Rows[i];
            if (dr["PrId"] == PId)
            {
                dt.Rows.Remove(dr);
            }
        }
        GVCart.DataSource = dt;
        GVCart.DataBind();
        Session.Add("Cart", dt);
    }
    protected void txtQnty_TextChanged(object sender, EventArgs e)
    {
        TextBox txt = sender as TextBox;
        GridViewRow row = txt.NamingContainer as GridViewRow;
        int index = row.RowIndex;
        DataTable dt = (DataTable)Session["Cart"];
        dt.Rows[index][3] = txt.Text;
        dt.Rows[index][5] = (Double.Parse(txt.Text) * Double.Parse(dt.Rows[index][4].ToString())).ToString();
        Session.Add("Cart", dt);
        GVCart.DataSource = dt;
        GVCart.DataBind();
    }
}

Please reply!!!

2
Contributors
1
Reply
10
Views
4 Years
Discussion Span
Last Post by geniusvishal
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.