
Здесь я использую один список флажков, в котором у нас есть следующий элемент
Apr-16,May-16,Jun-16,jul-16,Aug-16,Sep-16,Oct-16,Nov-16,Dec-16,Jan-16,Feb-16,Mar-16
Когда мы выбираем флажок за 16 апреля из списка cheboxlist, Gridview показывает ежемесячную плату за 16 апреля, а когда мы выбираем 16 апреля, 16 мая, тогда Gridview показывает подробную информацию о сборах за 16 апреля, 16 мая.
Когда мы выбираем 16 мая, 16 июня, 16 июля, тогда Gridview показывает 16 мая, 16 июня, 16 июля. Подробности о трех комиссиях.
Мне нужен результат:

Теперь я хочу посчитать сумму определенного столбца в моем представлении сетки
Вот мой код:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;
namespace egurkul
{
[Serializable]
public class field
{
public string duemonth { get; set; }
public decimal Admission_Fee { get; set; }
public decimal Prospectus_Registration_Fee { get; set; }
public decimal Maintenance_Fee { get; set; }
public decimal Computer_Fee { get; set; }
public decimal Examination_Fee { get; set; }
public decimal Tution_Fee { get; set; }
}
public partial class feeRecipt : System.Web.UI.Page
{
SqlCommand cmd;
SqlConnection con;
string duemonth;
int i;
decimal TotalAdmission_Fee, TotalProspectus_Registration_Fee, TotalMaintenance_Fee, TotalComputer_Fee, TotalExamination_Fee, TotalTution_Fee;
decimal Admission_Fee, Prospectus_Registration_Fee, Maintenance_Fee, Computer_Fee, Examination_Fee, Tution_Fee;
DataTable dt;
List data = null;
decimal Total = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
getddlclass();
bindchbxlstduedate();
}
}
public void getddlclass()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["con1"].ConnectionString;
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select *from class", con);
DataSet ds = new DataSet();
da.Fill(ds);
ddlclassname.DataSource = ds;
ddlclassname.DataTextField = "class_name";
ddlclassname.DataValueField = "class_id";
ddlclassname.DataBind();
ddlclassname.Items.Insert(0, new ListItem("--Select--", "0"));
con.Close();
}
public void bindchbxlstduedate()
{
using (SqlConnection conn = new SqlConnection())
{
con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["con1"].ConnectionString;
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "Readduedat";
cmd.CommandType = CommandType.StoredProcedure;
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
ListItem item = new ListItem();
item.Text = sdr["duemonth"].ToString();
item.Value = sdr["duedateid"].ToString();
chbxlstduedate.Items.Add(item);
}
}
con.Close();
}
}
protected void chbxlstduedate_SelectedIndexChanged(object sender, EventArgs e)
{
for (i = 0; i < chbxlstduedate.Items.Count; i++)
{
if (chbxlstduedate.Items.Selected)
{
duemonth = Convert.ToString(chbxlstduedate.Items);
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["con1"].ConnectionString;
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "readfeeshead";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
cmd.Parameters.AddWithValue("@duemonth", duemonth);
cmd.Parameters.AddWithValue("@classname", Convert.ToString(ddlclassname.SelectedItem));
cmd.Parameters.AddWithValue("@feecatename", Convert.ToString(ddlstcategory.SelectedItem));
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
duemonth1 = sdr["duemonth"].ToString();
Admission_Fee1 = sdr["Admission_Fee"].ToString();
Prospectus_Registration_Fee1 = sdr["Prospectus_Registration_Fee"].ToString();
Maintenance_Fee1 = sdr["Maintenance_Fee"].ToString();
Computer_Fee1 = sdr["Computer_Fee"].ToString();
Examination_Fee1 =sdr["Examination_Fee"].ToString();
Tution_Fee1 = sdr["Tution_Fee"].ToString();
}
}
con.Close();
if (data == null)
data = new List();
field f1 = new field();
f1.duemonth = duemonth1;
if (Admission_Fee1 == "")
{
f1.Admission_Fee = Convert.ToDecimal(0);
}
else
{
f1.Admission_Fee = Convert.ToDecimal(Admission_Fee1);
}
if (Prospectus_Registration_Fee1 == "")
{
f1.Prospectus_Registration_Fee = Convert.ToDecimal(0);
}
else
{
f1.Prospectus_Registration_Fee = Convert.ToDecimal(Prospectus_Registration_Fee1);
}
if (Maintenance_Fee1 == "")
{
f1.Maintenance_Fee = Convert.ToDecimal(0);
}
else
{
f1.Maintenance_Fee = Convert.ToDecimal(Maintenance_Fee1);
}
if (Computer_Fee1 == "")
{
f1.Computer_Fee = Convert.ToDecimal(0);
}
else
{
f1.Computer_Fee = Convert.ToDecimal(Computer_Fee1);
}
if (Examination_Fee1 == "")
{
f1.Examination_Fee = Convert.ToDecimal(0);
}
else
{
f1.Examination_Fee = Convert.ToDecimal(Examination_Fee1);
}
if (Tution_Fee1 == "")
{
f1.Tution_Fee = Convert.ToDecimal(0);
}
else
{
f1.Tution_Fee = Convert.ToDecimal(Tution_Fee1);
}
data.Add(f1);
ViewState["_data"] = data;
GridView1.DataSource = data;
GridView1.DataBind();
}
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataRowView dtview = e.Row.DataItem as DataRowView;
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbladmissionfee = (Label)e.Row.FindControl("lbladmissionfee");
TotalAdmission_Fee = TotalAdmission_Fee + Convert.ToDecimal(lbladmissionfee.Text);
Label lblcomputerfee = (Label)e.Row.FindControl("lblcomputerfee");
TotalComputer_Fee = TotalComputer_Fee + Convert.ToDecimal(lblcomputerfee.Text);
Label lblExaminationfee = (Label)e.Row.FindControl("lblExaminationfee");
TotalExamination_Fee = TotalExamination_Fee + Convert.ToDecimal(lblExaminationfee.Text);
Label lblMaintenancefee = (Label)e.Row.FindControl("lblMaintenancefee");
TotalMaintenance_Fee = TotalMaintenance_Fee + Convert.ToDecimal(lblMaintenancefee.Text);
Label lblProsepectusRegistrationFee = (Label)e.Row.FindControl("lblProsepectusRegistrationFee");
TotalProspectus_Registration_Fee = TotalProspectus_Registration_Fee +Convert.ToDecimal(lblProsepectusRegistrationFee.Text);
Label lblTutionfee = (Label)e.Row.FindControl("lblTutionfee");
TotalTution_Fee = TotalTution_Fee + Convert.ToDecimal(lblTutionfee.Text);
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lbl_totaladmissionfee = (Label)e.Row.FindControl("lbl_totaladmissionfee");
lbl_totaladmissionfee.Text = TotalAdmission_Fee.ToString();
Label lbl_totalcomputerfee = (Label)e.Row.FindControl("lbl_totalcomputerfee");
lbl_totalcomputerfee.Text = TotalComputer_Fee.ToString();
Label lbl_Totalexaminationfee = (Label)e.Row.FindControl("lbl_Totalexaminationfee");
lbl_Totalexaminationfee.Text = TotalExamination_Fee.ToString();
Label lbl_totalmaintenancefee = (Label)e.Row.FindControl("lbl_totalmaintenancefee");
lbl_totalmaintenancefee.Text = TotalMaintenance_Fee.ToString();
Label lbl_TotalProsepectusRegistrationFee = (Label)e.Row.FindControl("lbl_TotalProsepectusRegistrationFee");
lbl_TotalProsepectusRegistrationFee.Text = TotalProspectus_Registration_Fee.ToString();
Label lbl_Totaltutionfee = (Label)e.Row.FindControl("lbl_Totaltutionfee");
lbl_Totaltutionfee.Text = TotalTution_Fee.ToString();
decimal alltotal = TotalTution_Fee + TotalProspectus_Registration_Fee + TotalMaintenance_Fee + TotalExamination_Fee + TotalComputer_Fee + TotalAdmission_Fee;
Label lbl_Totalsamount = (Label)e.Row.FindControl("lbl_Totalsamount");
lbl_Totalsamount.Text = alltotal.ToString();
}
}
Подробнее здесь: https://stackoverflow.com/questions/359 ... ng-c-sharp
Мобильная версия