如何解决ASP.net 应用程序未使用 WCF 服务将总计显示到网格视图控件中
我正在尝试使用网格视图控件将总计显示到 asp.net Web 应用程序中。我正在使用 WCF 服务通过使用 ID(帐号)检索数据表单数据库。我使用 Row Data Bound 事件来计算总数,但问题是不显示总计。
这是 WCF 代码。
public DataSet DepositDetails(Current_Account_Deposit_Details current_Account_Deposit_Details)
{
sqlConnection con = new sqlConnection(ConnectionString);
con.open();
sqlCommand cmd = new sqlCommand("select * from Current_Account_Deposit where Account_Number=@Account_Number",con);
cmd.Parameters.AddWithValue("@Account_Number",current_Account_Deposit_Details.Account_Number);
sqlDataAdapter sda = new sqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
cmd.ExecuteNonQuery();
con.Close();
return ds;
}
这是网络应用程序的代码。
protected void Button1_Click(object sender,EventArgs e)
{
MyService.HalifaxCurrentAccountServiceClient my = new MyService.HalifaxCurrentAccountServiceClient("NetTcpBinding_IHalifaxCurrentAccountService");
MyService.Current_Account_Deposit_Details cd = new MyService.Current_Account_Deposit_Details();
cd.Account_Number = TextBox1.Text;
DataSet ds = new DataSet();
ds = my.DepositDetails(cd);
GridView1.DataSource = ds;
GridView1.DataBind();
}
int totalDeposit = 0;
protected void GridView1_RowDataBound(object sender,GridViewRowEventArgs e)
{
// Loop thru each data row and compute total unit price and quantity sold
if (e.Row.RowType == DataControlRowType.DaTarow)
{
totalDeposit += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem,"Amount"));
}
// display totals in the gridview footer
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[1].Text = "Grand Total";
e.Row.Cells[1].Font.Bold = true;
e.Row.Cells[3].Text = totalDeposit.ToString();
e.Row.Cells[3].Font.Bold = true;
}
}
}
这是结果的屏幕截图。
解决方法
是否要获取 datagridview 中的行数?
如果是,尝试dataGridView1.Rows.Count获取总行数,然后使用控件显示。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。