views:

640

answers:

1

Hi all,

We are using dynamic text box inside the gridview. When tab key pressed on each textbox inside the grid we need to do some calculation using total value from the database and value in the previous textbox and the result should be displayed in the next textbox.

Regards Geetha

+1  A: 

Hopefully this example should get you on your way. In the grid, set the 2 textbox columns as template columns so that you can define the textbox id’s and OnTextChanged event. The AutoPostBack attribute is also important so that the textbox does post back when the user tabs out. In the code behind you need to handle the OnTextChanged event and get references to the textboxes using the FindControl method.

Mark up:

    <asp:GridView ID="GridView1" runat="server">
        <Columns>
            <asp:TemplateField>
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="Texbox_Changed" AutoPostBack="true" ></asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

Code behind:

Protected Sub Texbox_Changed(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim Param As String = CType(sender, TextBox).Text
    Dim Result As String = Param 'TODO: perform calculation
    CType(GridView1.Rows(GridView1.EditIndex).FindControl("TextBox2"), TextBox).Text = Result
End Sub
rip