-------------------------------------------------Asp.net code----------------------------------------------------
<form id="form1" runat="server">
<div class="card">
<table>
<tr>
<td>
<asp:Label ID="lblTotalCaption" runat="server" Visible="false">Total Salary:</asp:Label>
</td>
<td>
<asp:Label ID="lblTotal" runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lblTotalAllownce" runat="server" Visible="false">Total Allownce:</asp:Label>
</td>
<td>
<asp:Label ID="lblTotaAllownce" runat="server"></asp:Label>
</td>
<td>
</td>
</tr>
</table>
<br />
<asp:GridView ID="gvEmpInfo" AutoGenerateColumns="False" CellPadding="4" runat="server"
BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkbox" runat="server" AutoPostBack="true" OnCheckedChanged="ChckedChanged"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="EmpId" DataField="EmpId" />
<asp:BoundField HeaderText="EmpName" DataField="Emp_Name" />
<asp:BoundField HeaderText="EmpAddress" DataField="Emp_Address" />
<asp:BoundField HeaderText="EmpDept" DataField="Emp_Department" />
<%--<asp:BoundField HeaderText="Salary" DataField="Salary" />--%>
<asp:TemplateField HeaderText="Salary">
<ItemTemplate>
<asp:Label ID="lblListPrice" runat="server" Text='<%#Eval("Salary")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OtherAllownce">
<ItemTemplate>
<asp:Label ID="lblOtherAllownce" runat="server" Text='<%#Eval("OtherAllownce")%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="#003399" Font-Bold="true" ForeColor="#CCCCFF" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SortedAscendingCellStyle BackColor="#EDF6F6" />
<SortedAscendingHeaderStyle BackColor="#0D4AC4" />
<SortedDescendingCellStyle BackColor="#D6DFDF" />
<SortedDescendingHeaderStyle BackColor="#002876" />
</asp:GridView>
</div>
</form>
-------------------------------------------------------C#.net code-----------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
namespace ProjectAspCSharp
{
public partial class GridViewSalaryCalculations : System.Web.UI.Page
{
SqlConnection con;
SqlDataAdapter adap;
DataTable dt;
String strConnString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridview();
}
}
public GridViewSalaryCalculations()
{
//strConnString = ConfigurationManager.ConnectionStrings("ConStr").ConnectionString();
strConnString = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
}
protected void BindGridview()
{
adap = new SqlDataAdapter("select * from EmployeeInformation", strConnString);
dt = new DataTable();
adap.Fill(dt);
gvEmpInfo.DataSource = dt;
gvEmpInfo.DataBind();
}
protected void ChckedChanged(object sender, EventArgs e)
{
try
{
int count = 0;
Decimal totalSalary = 0;
Decimal totalOther = 0;
lblTotal.Text = "";
lblTotaAllownce.Text = "";
lblTotalCaption.Visible = false;
lblTotalAllownce.Visible = false;
foreach (GridViewRow rw in gvEmpInfo.Rows)
{
CheckBox chkBx = (CheckBox)rw.FindControl("chkbox");
if (chkBx.Checked)
{
count++;
Decimal Salary = Convert.ToDecimal(((Label)rw.FindControl("lblListPrice")).Text);
Decimal OtherAllownce = Convert.ToDecimal(((Label)rw.FindControl("lblOtherAllownce")).Text);
totalSalary = Convert.ToDecimal((totalSalary + Convert.ToDecimal(Salary)));
totalOther = Convert.ToDecimal((totalOther + Convert.ToDecimal(OtherAllownce)));
chkBx.Checked = true;
lblTotal.Text = totalSalary.ToString();
lblTotaAllownce.Text = totalOther.ToString();
lblTotalCaption.Visible = true;
lblTotalAllownce.Visible = true;
}
}
}
catch (Exception ex)
{
}
}
}
}
----------------------------------------------vb.net code------------------------------------------------------
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Configuration
Public Class CheckBoxesCalkulations
Inherits System.Web.UI.Page
Private con As SqlConnection
Private adap As SqlDataAdapter
Private dt As DataTable
Dim strConnString As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
BindGridview()
End If
End Sub
Public Sub New()
strConnString = ConfigurationManager.ConnectionStrings("ConStr").ConnectionString
End Sub
Protected Sub BindGridview()
adap = New SqlDataAdapter("select * from EmployeeInformation", strConnString)
dt = New DataTable()
adap.Fill(dt)
gvEmpInfo.DataSource = dt
gvEmpInfo.DataBind()
End Sub
Protected Sub ChckedChanged(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim count As Integer = 0
Dim totalSalary As Decimal = 0
Dim totalOther As Decimal = 0
lblTotal.Text = ""
lblTotaAllownce.Text = ""
lblTotalCaption.Visible = False
lblTotalAllownce.Visible = False
For Each rw As GridViewRow In gvEmpInfo.Rows
Dim chkBx As CheckBox = CType(rw.FindControl("chkbox"), CheckBox)
If chkBx.Checked Then
count += 1
Dim Salary As Decimal = Convert.ToDecimal((CType(rw.FindControl("lblListPrice"), Label)).Text)
Dim OtherAllownce As Decimal = Convert.ToDecimal((CType(rw.FindControl("lblOtherAllownce"), Label)).Text)
totalSalary = Convert.ToDecimal((totalSalary + Convert.ToDecimal(Salary)))
totalOther = Convert.ToDecimal((totalOther + Convert.ToDecimal(OtherAllownce)))
chkBx.Checked = True
lblTotal.Text = totalSalary.ToString()
lblTotaAllownce.Text = totalOther.ToString
lblTotalCaption.Visible = True
lblTotalAllownce.Visible = True
End If
Next
Catch ex As Exception
End Try
' GetSelectedRows()
' BindSecondGrid()
End Sub
End Class
<form id="form1" runat="server">
<div class="card">
<table>
<tr>
<td>
<asp:Label ID="lblTotalCaption" runat="server" Visible="false">Total Salary:</asp:Label>
</td>
<td>
<asp:Label ID="lblTotal" runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lblTotalAllownce" runat="server" Visible="false">Total Allownce:</asp:Label>
</td>
<td>
<asp:Label ID="lblTotaAllownce" runat="server"></asp:Label>
</td>
<td>
</td>
</tr>
</table>
<br />
<asp:GridView ID="gvEmpInfo" AutoGenerateColumns="False" CellPadding="4" runat="server"
BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkbox" runat="server" AutoPostBack="true" OnCheckedChanged="ChckedChanged"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="EmpId" DataField="EmpId" />
<asp:BoundField HeaderText="EmpName" DataField="Emp_Name" />
<asp:BoundField HeaderText="EmpAddress" DataField="Emp_Address" />
<asp:BoundField HeaderText="EmpDept" DataField="Emp_Department" />
<%--<asp:BoundField HeaderText="Salary" DataField="Salary" />--%>
<asp:TemplateField HeaderText="Salary">
<ItemTemplate>
<asp:Label ID="lblListPrice" runat="server" Text='<%#Eval("Salary")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OtherAllownce">
<ItemTemplate>
<asp:Label ID="lblOtherAllownce" runat="server" Text='<%#Eval("OtherAllownce")%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="#003399" Font-Bold="true" ForeColor="#CCCCFF" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SortedAscendingCellStyle BackColor="#EDF6F6" />
<SortedAscendingHeaderStyle BackColor="#0D4AC4" />
<SortedDescendingCellStyle BackColor="#D6DFDF" />
<SortedDescendingHeaderStyle BackColor="#002876" />
</asp:GridView>
</div>
</form>
-------------------------------------------------------C#.net code-----------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
namespace ProjectAspCSharp
{
public partial class GridViewSalaryCalculations : System.Web.UI.Page
{
SqlConnection con;
SqlDataAdapter adap;
DataTable dt;
String strConnString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridview();
}
}
public GridViewSalaryCalculations()
{
//strConnString = ConfigurationManager.ConnectionStrings("ConStr").ConnectionString();
strConnString = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
}
protected void BindGridview()
{
adap = new SqlDataAdapter("select * from EmployeeInformation", strConnString);
dt = new DataTable();
adap.Fill(dt);
gvEmpInfo.DataSource = dt;
gvEmpInfo.DataBind();
}
protected void ChckedChanged(object sender, EventArgs e)
{
try
{
int count = 0;
Decimal totalSalary = 0;
Decimal totalOther = 0;
lblTotal.Text = "";
lblTotaAllownce.Text = "";
lblTotalCaption.Visible = false;
lblTotalAllownce.Visible = false;
foreach (GridViewRow rw in gvEmpInfo.Rows)
{
CheckBox chkBx = (CheckBox)rw.FindControl("chkbox");
if (chkBx.Checked)
{
count++;
Decimal Salary = Convert.ToDecimal(((Label)rw.FindControl("lblListPrice")).Text);
Decimal OtherAllownce = Convert.ToDecimal(((Label)rw.FindControl("lblOtherAllownce")).Text);
totalSalary = Convert.ToDecimal((totalSalary + Convert.ToDecimal(Salary)));
totalOther = Convert.ToDecimal((totalOther + Convert.ToDecimal(OtherAllownce)));
chkBx.Checked = true;
lblTotal.Text = totalSalary.ToString();
lblTotaAllownce.Text = totalOther.ToString();
lblTotalCaption.Visible = true;
lblTotalAllownce.Visible = true;
}
}
}
catch (Exception ex)
{
}
}
}
}
----------------------------------------------vb.net code------------------------------------------------------
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Configuration
Public Class CheckBoxesCalkulations
Inherits System.Web.UI.Page
Private con As SqlConnection
Private adap As SqlDataAdapter
Private dt As DataTable
Dim strConnString As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
BindGridview()
End If
End Sub
Public Sub New()
strConnString = ConfigurationManager.ConnectionStrings("ConStr").ConnectionString
End Sub
Protected Sub BindGridview()
adap = New SqlDataAdapter("select * from EmployeeInformation", strConnString)
dt = New DataTable()
adap.Fill(dt)
gvEmpInfo.DataSource = dt
gvEmpInfo.DataBind()
End Sub
Protected Sub ChckedChanged(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim count As Integer = 0
Dim totalSalary As Decimal = 0
Dim totalOther As Decimal = 0
lblTotal.Text = ""
lblTotaAllownce.Text = ""
lblTotalCaption.Visible = False
lblTotalAllownce.Visible = False
For Each rw As GridViewRow In gvEmpInfo.Rows
Dim chkBx As CheckBox = CType(rw.FindControl("chkbox"), CheckBox)
If chkBx.Checked Then
count += 1
Dim Salary As Decimal = Convert.ToDecimal((CType(rw.FindControl("lblListPrice"), Label)).Text)
Dim OtherAllownce As Decimal = Convert.ToDecimal((CType(rw.FindControl("lblOtherAllownce"), Label)).Text)
totalSalary = Convert.ToDecimal((totalSalary + Convert.ToDecimal(Salary)))
totalOther = Convert.ToDecimal((totalOther + Convert.ToDecimal(OtherAllownce)))
chkBx.Checked = True
lblTotal.Text = totalSalary.ToString()
lblTotaAllownce.Text = totalOther.ToString
lblTotalCaption.Visible = True
lblTotalAllownce.Visible = True
End If
Next
Catch ex As Exception
End Try
' GetSelectedRows()
' BindSecondGrid()
End Sub
End Class
No comments:
Post a Comment