电商分销主要做什么,google seo教程,外贸订单流失严重,网站建设价格比较GridView加入自动求和求平均值小计效果图#xff1a;解决方案#xff1a;
private double sum 0; //取指定列的数据和#xff0c;你要根据具体情况对待可能你要处理的是int
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e){if (e.Row.R… GridView加入自动求和求平均值小计效果图解决方案
private double sum 0; //取指定列的数据和你要根据具体情况对待可能你要处理的是int
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e){if (e.Row.RowIndex 0){sum Convert.ToDouble(e.Row.Cells[6].Text);}else if (e.Row.RowType DataControlRowType.Footer){e.Row.Cells[5].Text 总薪水为;e.Row.Cells[6].Text sum.ToString();e.Row.Cells[3].Text 平均薪水为;e.Row.Cells[4].Text ((int)(sum / GridView1.Rows.Count)).ToString();}}
后台全部代码
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Drawing;
public partial class Default7 : System.Web.UI.Page
{SqlConnection sqlcon;SqlCommand sqlcom;string strCon Data Source(local);Database北风贸易;Uidsa;Pwdsa;protected void Page_Load(object sender, EventArgs e){if (!IsPostBack){bind();}}protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e){GridView1.EditIndex e.NewEditIndex;bind();}protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e){sqlcon new SqlConnection(strCon);string sqlstr update 飞狐工作室 set 姓名 ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() ,家庭住址 ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() where 身份证号码 GridView1.DataKeys[e.RowIndex].Value.ToString() ;sqlcom new SqlCommand(sqlstr, sqlcon);sqlcon.Open();sqlcom.ExecuteNonQuery();sqlcon.Close();GridView1.EditIndex -1;bind();}protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e){GridView1.EditIndex -1;bind();}public void bind(){string sqlstr select top 5 * from 编程中国社区;sqlcon new SqlConnection(strCon);SqlDataAdapter myda new SqlDataAdapter(sqlstr, sqlcon);DataSet myds new DataSet();sqlcon.Open();myda.Fill(myds, 编程中国社区);GridView1.DataSource myds;GridView1.DataKeyNames new string[] { 身份证号码 };GridView1.DataBind();sqlcon.Close();}private double sum 0; //取指定列的数据和protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e){if (e.Row.RowIndex 0){sum Convert.ToDouble(e.Row.Cells[6].Text);}else if (e.Row.RowType DataControlRowType.Footer){e.Row.Cells[5].Text 总薪水为;e.Row.Cells[6].Text sum.ToString();e.Row.Cells[3].Text 平均薪水为;e.Row.Cells[4].Text ((int)(sum / GridView1.Rows.Count)).ToString();}}
}
前台唯一的花头就是设置ShowFooterTrue 否则默认表头为隐藏的
asp:GridView IDGridView1 runatserver AutoGenerateColumnsFalse CellPadding3 OnRowEditingGridView1_RowEditingOnRowUpdatingGridView1_RowUpdating OnRowCancelingEditGridView1_RowCancelingEdit BackColorWhite BorderColor#CCCCCC BorderStyleNone BorderWidth1px Font-Size12px OnRowDataBoundGridView1_RowDataBound ShowFooterTrue FooterStyle BackColorWhite ForeColor#000066 /Columnsasp:CommandField HeaderText编辑 ShowEditButtonTrue /asp:BoundField DataField身份证号码 HeaderText编号 ReadOnlyTrue /asp:BoundField DataField姓名 HeaderText姓名 /asp:BoundField DataField出生日期 HeaderText邮政编码 /asp:BoundField DataField家庭住址 HeaderText家庭住址 /asp:BoundField DataField邮政编码 HeaderText邮政编码 /asp:BoundField DataField起薪 HeaderText起薪 //ColumnsRowStyle ForeColor#000066 /SelectedRowStyle BackColor#669999 Font-BoldTrue ForeColorWhite /PagerStyle BackColorWhite ForeColor#000066 HorizontalAlignLeft CssClassms-formlabel DataGridFixedHeader/HeaderStyle BackColor#006699 Font-BoldTrue ForeColorWhite //asp:GridView转载于:https://www.cnblogs.com/shangshen/p/3592197.html