Have you implemented the textboxes as EditItemTemplate in your code? If so, make sure to include the OnTextChanged event - Textbox1_OnTextChanged
within the textboxes in the EditItemTemplate.
<asp:DataGrid ID="Grid" runat="server">
<Columns>
<asp:TemplateColumn>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" OnLoad="TextBox1_Load" OnTextChanged="Textbox1_OnTextChanged"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
To calculate the sum of values on the server side, ensure that you also add the Load event (Textbox1_OnLoad) in the EditItemTemplate for the textbox. This will bind the clientside event of the text box properly.
protected void TextBox1_Load(object sender, EventArgs e)
{
TextBox newTb = sender as TextBox;
if (newTb != null)
{
newTb.Attributes.Add("onChange", "sumup(this)");
}
}
Using Javascript, you can handle the sumup event and retrieve the values of the textboxes using the this object to perform addition operations. Remember to return false at the end of the sumup function to prevent postback if the javascript support is enabled.
In case javascript support is disabled, the method will not be executed, and the postback will occur automatically.
We hope these steps provide a clearer understanding of how to achieve the desired functionality.
Best Regards,
Lakxman Kumar C