Vishal Torne
Vishal Torne

Reputation: 366

editing the same cell in the gridview

hello i am creating a shopping application , I have a shopping cart in that i have some columns which are add from the code behind and some columns are of template fields which are not present in the database but want use in future.

this is my shopping cart

code :

<asp:GridView ID="GridViewProduct" runat="server" CellPadding="5" CssClass="grid"
    ForeColor="#333333" OnRowCreated="GridViewProduct_RowCreated" OnRowDataBound="GridViewProduct_RowDataBound"
    ShowFooter="True" CellSpacing="1" 
    onrowupdating="GridViewProduct_RowUpdating">
    <AlternatingRowStyle BackColor="White" />
    <Columns>
        <asp:ButtonField Text="Remove From Cart" CommandName="RemoveFromCart" />
        <asp:TemplateField HeaderText="Quantity">
            <ItemTemplate>
                <asp:TextBox ID="TextBoxQuantity" runat="server" Width="50px">1</asp:TextBox><br />
                <asp:LinkButton ID="LinkButtonEditQuantity" runat="server"  CommandName="EditTextBox">edit</asp:LinkButton>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:LinkButton ID="LinkButtonUpdate" runat="server">Update</asp:LinkButton>
            </EditItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Total Price">
            <ItemTemplate>
                <asp:Label ID="LabelTotalPrice" runat="server" Text="0"></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <EditRowStyle BackColor="#7C6F57" />
    <FooterStyle BackColor="#1C5E55" ForeColor="White" Font-Bold="True" />
    <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#E3EAEB" />
    <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
    <SortedAscendingCellStyle BackColor="#F8FAFA" />
    <SortedAscendingHeaderStyle BackColor="#246B61" />
    <SortedDescendingCellStyle BackColor="#D4DFE1" />
    <SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>

enter image description here

i have a edit link button in the template field and the update link button in the editItem template and textbox above it so as to edit the textbox when a person clicks the edit link button.

My Question is that : How can i edit the textbox in the same column instead of whole row.

and which method should i use of the to achieve to editing the same cell rowupdating,rowcommand and save the values in session and multiply the edited value as quantity and unit price to show in the total price rows of the gridview .

please help me to implement right way to implement this as i am stuck with this for many days.. please

Upvotes: 0

Views: 794

Answers (1)

Marcianin
Marcianin

Reputation: 471

on your gridview templates, look at the EditRowTemplate, you will see that it contains all the editable controls (most likely textboxes) delete the textboxes and add Labels instead and bind them to your datasource. That way the data is still displayed but wont be editable (except for the control that you want to be edited)

Try it and let me know if you need more help.

Upvotes: 1

Related Questions