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!!!

Did you have autopostback="true" attribute inside your textbox tag??

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.