Hi @RAVI,
Firstly, you need to set MasterPageFile. Like this . <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.Master"…
And then set your GridView control in Content
, simple code below:
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.Master" CodeFile="Default.aspx.cs" Inherits="WebApplication10._Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="SKIN TYPE">
<ItemTemplate>
<asp:Label ID="L1" runat="server" Text='<%#Eval("Field1") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Font-Size="14px" ForeColor="Teal" Width="60px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="HP - SP - TOTAL">
<ItemTemplate>
<asp:TextBox ID="HP" runat="server" Width="40px" CssClass="hp-textbox"></asp:TextBox>
<asp:TextBox ID="SP" runat="server" Width="40px" CssClass="sp-textbox"></asp:TextBox>
<asp:TextBox ID="HP_SP_TOTAL" runat="server" Width="60px" CssClass="hp-sp-total-textbox"></asp:TextBox>
</ItemTemplate>
<HeaderStyle Font-Size="14px" ForeColor="Teal" Width="60px" />
<ItemStyle Width="200px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="HS - SS - TOTAL">
<ItemTemplate>
<asp:TextBox ID="HS" runat="server" Width="40px" CssClass="hs-textbox"></asp:TextBox>
<asp:TextBox ID="SS" runat="server" Width="40px" CssClass="ss-textbox"></asp:TextBox>
<asp:TextBox ID="HS_SS_TOTAL" runat="server" Width="60px" CssClass="hs-ss-total-textbox"></asp:TextBox>
</ItemTemplate>
<HeaderStyle Font-Size="14px" ForeColor="Teal" Width="60px" />
<ItemStyle Width="200px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="HA-HB">
<ItemTemplate>
<asp:TextBox ID="HP1" runat="server" Width="40px" CssClass="hp1-textbox" Text='<%#Eval("Field2") %>'></asp:TextBox>
<asp:TextBox ID="SP1" runat="server" Width="40px" CssClass="sp1-textbox" Text='<%#Eval("Field3") %>'></asp:TextBox>
</ItemTemplate>
<HeaderStyle Font-Size="14px" ForeColor="Teal" Width="60px" />
<ItemStyle Width="200px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
<script src=https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js></script>
<script>
$(document).ready(function () {
$('.hp-sp-total-textbox, .hs-textbox, .ss-textbox, .hs-ss-total-textbox').prop('readonly', true);
$(document).on('keyup', '.hp-textbox, .sp-textbox', function () {
var $row = $(this).closest('tr');
var hp = parseFloat($row.find('.hp-textbox').val()) || 0;
var sp = parseFloat($row.find('.sp-textbox').val()) || 0;
var hp1 = parseFloat($row.find('.hp1-textbox').val()) || 0;
var sp1 = parseFloat($row.find('.sp1-textbox').val()) || 0;
if (this.className.includes('hp-textbox') && $row.find('.sp-textbox').val() === '') {
$row.find('.sp-textbox').val('0');
}
if (this.className.includes('sp-textbox') && $row.find('.hp-textbox').val() === '') {
$row.find('.hp-textbox').val('0');
}
var hs = hp * hp1;
var ss = sp * sp1;
$row.find('.hs-textbox').val(hs.toFixed(2));
$row.find('.ss-textbox').val(ss.toFixed(2));
$row.find('.hp-sp-total-textbox').val((hp + sp).toFixed(2));
$row.find('.hs-ss-total-textbox').val((hs + ss).toFixed(2));
});
});
</script>
</asp:Content>
Result:
Best regards,
Xudong Peng
If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.