Question : Text_Changed for Gridview

I have a gridview that reads data from an object datasource. There is only 1 editable textbox per row. Think of it like a spreadsheet.

Row Layout:
Column 1: ID
Column 2: ProductName
Column 3: Price
Column 4: Qty (textbox - ONLY thing that's editable)
Column 5: Total (needs to auto-calculate (price X qty) AFTER Qty is input.)

When a user puts in a value for Price (textbox) I want to calculate the total in the "lblTotal" label in the last column. In addition, I also want to make sure that if the user hit TAB to leave the textbox it goes to the Qty textbox on the NEXT row.

How can I do this? Code examples please.

Answer : Text_Changed for Gridview

e.g. here:
        <asp:GridView ID="GridView5"  runat="server"  AutoGenerateColumns="False"
            DataSourceID="SqlDataSource1" DataKeyNames="ProductId">
            <Columns>
                <asp:BoundField DataField="ProductName" HeaderText="Product Name" />
                <asp:BoundField DataField="UnitPrice" HeaderText="Unit Price" />
                <asp:TemplateField HeaderText="Quantity">
                <ItemTemplate>
                    <asp:TextBox ID="txtQuantity" runat="server" OnTextChanged="txtQuantity_TextChanged" Text="0" AutoPostBack="true"> </asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Price">
                <ItemTemplate>
                    <asp:Label ID="lblPrice" runat="server" Text=""></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

protected void txtQuantity_TextChanged(object sender, EventArgs e)
    {
        TextBox tb = (TextBox) sender;
        GridViewRow row =(GridViewRow) tb.NamingContainer;
        decimal unitprice = Convert.ToDecimal(row.Cells[1].Text);
        int quantity = Convert.ToInt32(tb.Text);
        Label lblPrice = (Label)row.FindControl("lblPrice");
        lblPrice.Text = (unitprice * quantity).ToString();
    }
Random Solutions  
 
programming4us programming4us