views:

27

answers:

0

I am unable to get the updated value of textbox within a listview when "Update" link button is clicked which calls a function.

  <asp:ListView ID="_lvCartItems" OnItemUpdating="CartPartItem_OnItemUpdating"
         OnItemDeleting="CartPartItem_OnItemDeleting" runat="server">

            <LayoutTemplate>
                <table width="900px" border="0" style="font-size: small">
                    <tr style="background: #DDDDDD;">
                        <th align="center" style="width:80px">Delete</th>
                        <th align="center" style="width:100px">Quantity</th>
                        <th align="center" valign="top">Part No. </th>
                        <th align="center" valign="top">Part Name </th>
                        <th align="center" valign="top">Total Price</th>
                    </tr>
                    <tr runat="server" id="itemPlaceholder"></tr>
                </table>                    
            </LayoutTemplate>
            <ItemTemplate>
                <tr>
                    <td align="center" style="width:80px">
                        <asp:LinkButton runat="server" ID="_lnbDelete" Text="Delete" CommandName="Delete" Font-Underline="True" ForeColor="Black" />
                    </td>
                    <td align="center" style="width:100px">
                        <asp:TextBox ID="_tbQuantity" Text='<%# Eval("quantity") %>' runat="server" MaxLength="2" Width="40px" />
                        <asp:LinkButton ID="_btnUpdateQty" runat="server" CommandName="Update" Text="Update" Font-Underline="True" ForeColor="Black"/>                            
                    </td>
                    <td align="center" style="width:150px">
                        <asp:Label ID="_lblPartNo" Text='<%# Eval("partItem.PartNo").ToString() %>' runat="server"/>
                    </td>
                    <td align="center" style="width:450px">
                        <asp:Label ID="_lblPartName" Text='<%# Eval("partItem.PartName").ToString() %>' runat="server"/>
                    </td>
                    <td align="center" style="width:120px">
                        <asp:Label ID="_lblTotalCost" Text='<%# "$" + Eval("totalCost").ToString() %>' runat="server"/>
                    </td>
                </tr>                
            </ItemTemplate>
    </asp:ListView>

and here is the function that triggers on clicking the "Update" link button

    protected void CartPartItem_OnItemUpdating(object sender, ListViewUpdateEventArgs e)
{
    //Remeber to handle value of 0 quantity
    Label _lblPartNo = (Label)_lvCartItems.Items[e.ItemIndex].FindControl("_lblPartNo");
    Part p = PartDataLoader.GetPartByPartNo(_lblPartNo.Text);
    cartList = (List<CartItem>)Session["partsInCart"];
    TextBox _tbQuantity = (TextBox)_lvCartItems.Items[e.ItemIndex].FindControl("_tbQuantity");

    int qty = Convert.ToInt32(_tbQuantity.Text.Trim().ToString());

    if (int.TryParse(_tbQuantity.Text.Trim().ToString(), out qty))
    {
        cartList[e.ItemIndex].quantity = qty;
    }
    else 
    {
        _lblMessage.Text = "Quantity has not been updated.";
    }        

    Session["partsInCart"] = cartList;
    _lvCartItems.DataSource = cartList;
    _lvCartItems.DataBind();
    ConvertToPrice();

}

I am having a problem retrieving the new value from text box. Pleas advise