I have problem dealing with EditItemTemplate. What I am trying to do is to update 'lowerIncomeBoundary' with the sum of amount of current value in tb1 and tb2 which is the sum of "lowerIncomeBoundary" and "upperIncomeBoundary". Appreciate if someone can provide me a way to access item in EditItemTemplate...

<asp:TemplateField HeaderText="Chargeable&lt;br/&gt;Income&lt;br/&gt;RM">
                <ItemTemplate>
                    <%# Eval("lowerIncomeBoundary")%><br /><%# Convert.ToInt32(Eval("upperIncomeBoundary")) - Convert.ToInt32(Eval("lowerIncomeBoundary")) %>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox Text='<%#Bind("lowerIncomeBoundary") %>' runat="server" ID="tb1"></asp:TextBox>
                    <asp:TextBox Text='<%#Bind("upperIncomeBoundary") %>' runat="server" ID="tb2"></asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateField>

I found a way to access item in EditItemTemplate. I even get to print the sum of tb1 and tb2 textbox but "upperIncomeBoundary" is not being update. Any idea why this is happening?

<asp:TemplateField HeaderText="Chargeable&lt;br/&gt;Income&lt;br/&gt;RM">
                <ItemTemplate>
                    <%# Eval("lowerIncomeBoundary")%><br /><%# Convert.ToInt32(Eval("upperIncomeBoundary")) - Convert.ToInt32(Eval("lowerIncomeBoundary")) %>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox Text='<%#Bind("lowerIncomeBoundary") %>' runat="server" ID="tb1"></asp:TextBox>
                    <asp:TextBox Text='<%#Convert.ToInt32(Eval("upperIncomeBoundary")) - Convert.ToInt32(Eval("lowerIncomeBoundary")) %>' runat="server" ID="tb2"></asp:TextBox>
                    <asp:TextBox Text='<%#Bind("upperIncomeBoundary") %>' runat="server" ID="tbTemp"></asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateField>

-------------------------------------------------------------------------------------
Code behind:

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int index = GridView1.EditIndex;
        GridViewRow row = GridView1.Rows[index];
        refreshRowUpdating();
        TextBox temp1 = (TextBox)row.FindControl("tb1");
        TextBox temp2 = (TextBox)row.FindControl("tb2");
        TextBox temp3 = (TextBox)row.FindControl("tbTemp");
        temp3.Text = Convert.ToString(Convert.ToInt32(temp1.Text) + Convert.ToInt32(temp2.Text));
        Response.Write(temp3.Text);
    }
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.