在DATAGRID中添加各列的统计项,生成一个统计行????? 请大家帮忙!老出错,说Input string was not in a correct format 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 HTML:<%@ Page language="c#" Codebehind="total.aspx.cs" AutoEventWireup="false" Inherits="myApp.total" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML> <HEAD> <title>total</title> <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="total" method="post" runat="server"> <FONT face="宋体"></FONT> <asp:datagrid id="grid" style="Z-INDEX: 101; LEFT: 57px; POSITION: absolute; TOP: 83px" runat="server" AutoGenerateColumns="False" ShowFooter="True" OnItemDataBound="MyDataGrid_ItemDataBound" FooterStyle-BackColor="Blue" FooterStyle-ForeColor="White" FooterStyle-Font-Bold="True" FooterStyle-Font-Size="10pt" FooterStyle-Font-Name="Verdana" HeaderStyle-BackColor="Blue" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="True" HeaderStyle-Font-Size="10pt" HeaderStyle-Font-Name="Verdana" ItemStyle-Font-Size="9pt" ItemStyle-Font-Name="Verdana" Gridlines="None" BorderWidth="1" BorderStyle="Solid" BorderColor="Black" CellSpacing="0" CellPadding="4" Width="267px"> <Columns> <asp:BoundColumn HeaderText="Title" DataField="title" /> <asp:BoundColumn HeaderText="Price" DataField="price" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Center" /> </Columns> </asp:datagrid> </form> </body></HTML>CS代码:using System;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;using System.Data;using System.Data.SqlClient;//using BDEServProj;namespace myApp{ public class total : Page { protected DataGrid MyGrid; protected System.Web.UI.WebControls.DataGrid grid; private double runningTotal = 0; // BDEServProj.BDEServClass aa= new BDEServProj.BDEServClass(); private void CalcTotal(string _price) { try { runningTotal += Double.Parse(_price); } catch { //A value was null } } public void MyDataGrid_ItemDataBound(object sender, DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { CalcTotal( e.Item.Cells[1].Text ); e.Item.Cells[1].Text = string.Format("{0:c}", Convert.ToDouble(e.Item.Cells[1].Text)); } else if(e.Item.ItemType == ListItemType.Footer ) { e.Item.Cells[0].Text="Total"; e.Item.Cells[1].Text = string.Format("{0:c}", runningTotal); } } private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if (!Page.IsPostBack) { SqlConnection cnn=new SqlConnection(@"Data Source=jerry;persist security info=False;user id=sa;password=;Initial Catalog=test"); SqlDataAdapter da=new SqlDataAdapter("SELECT title, price FROM total WHERE 1=1", cnn); DataSet ds = new DataSet(); da.Fill(ds, "total"); this.DataGrid1.DataSource = ds; this.DataGrid1.DataMember = "total"; this.DataGrid1.DataBind(); } } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { CalcTotal( e.Item.Cells[1].Text); e.Item.Cells[1].Text = string.Format("{0:c}", Convert.ToDouble(e.Item.Cells[1].Text)); } else if(e.Item.ItemType == ListItemType.Footer ) { e.Item.Cells[0].Text="Total"; e.Item.Cells[1].Text = string.Format("{0:c}", runningTotal); } } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> #endregion }} 是不是你的格式不正确?http://eu.webmatrixhosting.net/sharp_c/forum/MessageInfo.aspx?MessageID=64 动软代码生成器怎么样呀? sql 怎么写 关于商品过期问题 asp.net中GridView实现自定义分页,不要gridview自带的,请高手提供完整代码 window.open 的问题,在线等,帮帮忙,谢谢 using()是怎么回事呀!! asp.net的母版页的背景不显示问题 [求助]请问在JavaScript中怎样实现多线程???? 还是页面转向的错误。请高手帮我看看。这是为什么呀! 关于网站标题! 大家认为.net 能走多远? ##### 500分求页面界面框架解决办法/实例!!! ##### 找志同道合的朋友!!!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>total</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="total" method="post" runat="server">
<FONT face="宋体"></FONT>
<asp:datagrid id="grid" style="Z-INDEX: 101; LEFT: 57px; POSITION: absolute; TOP: 83px" runat="server"
AutoGenerateColumns="False" ShowFooter="True" OnItemDataBound="MyDataGrid_ItemDataBound" FooterStyle-BackColor="Blue"
FooterStyle-ForeColor="White" FooterStyle-Font-Bold="True" FooterStyle-Font-Size="10pt" FooterStyle-Font-Name="Verdana"
HeaderStyle-BackColor="Blue" HeaderStyle-ForeColor="White" HeaderStyle-Font-Bold="True" HeaderStyle-Font-Size="10pt"
HeaderStyle-Font-Name="Verdana" ItemStyle-Font-Size="9pt" ItemStyle-Font-Name="Verdana" Gridlines="None"
BorderWidth="1" BorderStyle="Solid" BorderColor="Black" CellSpacing="0" CellPadding="4" Width="267px">
<Columns>
<asp:BoundColumn HeaderText="Title" DataField="title" />
<asp:BoundColumn HeaderText="Price" DataField="price" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Center" />
</Columns>
</asp:datagrid>
</form>
</body>
</HTML>CS代码:using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Data.SqlClient;
//using BDEServProj;namespace myApp
{
public class total : Page
{
protected DataGrid MyGrid;
protected System.Web.UI.WebControls.DataGrid grid;
private double runningTotal = 0;
// BDEServProj.BDEServClass aa= new BDEServProj.BDEServClass();
private void CalcTotal(string _price)
{
try
{
runningTotal += Double.Parse(_price);
}
catch
{
//A value was null
}
}
public void MyDataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
CalcTotal( e.Item.Cells[1].Text );
e.Item.Cells[1].Text = string.Format("{0:c}", Convert.ToDouble(e.Item.Cells[1].Text));
}
else if(e.Item.ItemType == ListItemType.Footer )
{
e.Item.Cells[0].Text="Total";
e.Item.Cells[1].Text = string.Format("{0:c}", runningTotal);
}
} private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (!Page.IsPostBack)
{
SqlConnection cnn=new SqlConnection(@"Data Source=jerry;persist security info=False;user id=sa;password=;Initial Catalog=test");
SqlDataAdapter da=new SqlDataAdapter("SELECT title, price FROM total WHERE 1=1", cnn);
DataSet ds = new DataSet();
da.Fill(ds, "total");
this.DataGrid1.DataSource = ds;
this.DataGrid1.DataMember = "total";
this.DataGrid1.DataBind();
}
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
} private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
CalcTotal( e.Item.Cells[1].Text);
e.Item.Cells[1].Text = string.Format("{0:c}", Convert.ToDouble(e.Item.Cells[1].Text));
}
else if(e.Item.ItemType == ListItemType.Footer )
{
e.Item.Cells[0].Text="Total";
e.Item.Cells[1].Text = string.Format("{0:c}", runningTotal);
}
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary> #endregion
}
}
http://eu.webmatrixhosting.net/sharp_c/forum/MessageInfo.aspx?MessageID=64