Hi,
how can I total up lblOrderAmount after clicking the save button in [GridView2]?
My goal is to update lblTotalAmount accordingly in [GridView1] TQ HTML
<div>
<asp:GridView ID="GridView1" runat="server" CssClass="table table-sorting table-hover table-bordered datatable" DataKeyNames="student_Id" AutoGenerateColumns="false" GridLines="None">
<Columns>
<asp:TemplateField HeaderText="Admission No">
<ItemTemplate>
<asp:GridView ID="GridView2" runat="server" CssClass="table table-sorting table-hover table-bordered datatable" AutoGenerateColumns="false" GridLines="None">
<Columns>
<asp:TemplateField HeaderText="Order Amount">
<ItemTemplate>
<asp:Label ID="lblOrderAmount" runat="server" Text='<%# Eval("OrderAmount") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Pay">
<ItemTemplate>
<asp:LinkButton ID="lnkBtnEdit" runat="server" Text="Update" CssClass="btn btn-info" OnClick="Display"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Admission No">
<ItemTemplate>
<asp:Label ID="lblstudent_Id" runat="server" Text='<%# Eval("student_Id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Amount">
<ItemTemplate>
<asp:Label ID="lblTotalAmount" runat="server" Text='<%# Eval("TotalAmount") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<div>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Student Fee Details</h4>
</div>
<div class="modal-body">
<div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
<div class="form-group">
<asp:Label ID="lblstudent" runat="server" Text="Admission No: "></asp:Label>
<asp:Label ID="lblstudentid" runat="server" Text=""></asp:Label>
</div>
<div class="form-group">
<asp:Label ID="lblAmount" runat="server" Text="Order Amount"></asp:Label>
<asp:TextBox ID="txtAmount" runat="server" CssClass="form-control"></asp:TextBox>
</div>
</div>
</div>
<div class="modal-footer">
<asp:Button ID="btnSave" runat="server" Text="Update" OnClick="btnSave_Click" CssClass="btn btn-info" />
<button type="button" class="btn btn-info" data-dismiss="modal">Close</button>
</div>
</div>
</div>
<script type='text/javascript'>
function openModal() {
$('[id*=myModal]').modal('show');
}
</script>
</div>
</div>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("student_Id"), New DataColumn("TotalAmount")})
dt.Rows.Add(101, 5200)
dt.Rows.Add(102, 6500)
GridView1.DataSource = dt
GridView1.DataBind()
End If
End Sub
Protected Sub Display(ByVal sender As Object, ByVal e As EventArgs)
Dim rowOrder As GridViewRow = TryCast((TryCast(sender, LinkButton)).NamingContainer, GridViewRow)
Me.txtAmount.Text = TryCast(rowOrder.FindControl("lblOrderAmount"), Label).Text
ClientScript.RegisterStartupScript(Me.[GetType](), "Pop", "openModal();", True)
End Sub
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs)
'total up of lblOrderAmount from GridView2 and update accordingly in GridView1
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim GridView2 As GridView = TryCast(e.Row.FindControl("GridView2"), GridView)
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("OrderAmount")})
dt.Rows.Add(RandomInteger(1000, 9999))
dt.Rows.Add(RandomInteger(1000, 9999))
dt.Rows.Add(RandomInteger(1000, 9999))
GridView2.DataSource = dt
GridView2.DataBind()
End If
End Sub
Public Function RandomInteger(ByVal LowerBoundary As Integer, ByVal UpperBoundary As Integer) As Integer
Randomize() 'Initialize the random-number generator
RandomInteger = (Rnd() * (UpperBoundary - LowerBoundary)) + LowerBoundary
End Function