I am currently working on a gridview with dynamically generated rows, each row containing text boxes and buttons. The goal is to update the database with values from the textboxes when UpdateBtn1 is clicked. Users should be able to either click the button or hit enter while editing the textboxes to trigger the update.
Here is my current progress:
<asp:GridView ID="InitialData" runat="server"
AutoGenerateColumns="False"
OnRowDataBound="gv_GridDataBound"
OnRowCommand="InitialRowButton_Click"
DataKeyNames="ID" OnSelectedIndexChanged="InitialData_SelectedIndexChanged">
<Columns>
<asp:TemplateField HeaderText="Update">
<ItemTemplate>
<asp:Button ID="UpdateBtn1" ButtonType="Button" Text="Update" runat="server"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" CommandName="Run_Update" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ReadOnly="true" HeaderText="Data" DataField="Data" />
<asp:BoundField ReadOnly="true" HeaderText="Data" DataField="Data" />
<asp:BoundField ReadOnly="true" HeaderText="Data" DataField="Data" />
<asp:BoundField ReadOnly="true" HeaderText="Data" DataField="Data" />
<asp:BoundField ReadOnly="true" HeaderText="Data" DataField="Data" />
<asp:TemplateField HeaderText="Input Textbox1">
<ItemTemplate>
<asp:Button ID="RequestBtn" CommandName="Get_Weight" HeaderText="Request Weight"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" runat="server" Text="Request Weight" />
<asp:TextBox ID="InputText1" runat="server" Text='<%# Eval("MEASURED_WEIGHT") %>' Width="50px" />
<asp:RegularExpressionValidator ID="RegularExpWeightBox"
ControlToValidate="InputText1" runat="server" ErrorMessage="Illegal"
ValidationExpression="^[0-9]{0,5}$" class="regExpress">
</asp:RegularExpressionValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:DropDownList ID="STATUSDDL" AppendDataBoundItems="True" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Input Textbox2">
<ItemTemplate>
<asp:TextBox ID="InputTextbox2" runat="server" TextMode="MultiLine" Width="200" Rows="2" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I have tried using the onclick event to trigger the button or a JavaScript function, but I couldn't target the correct row's button. Any assistance would be highly appreciated.