Dynamic textbox inside gridview tab key press
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 开发者_如何学JAVAvalue in the previous textbox and the result should be displayed in the next textbox.
Regards Geetha
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
精彩评论