protected void CalculateExtendPrice(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[8].Text != null && e.Row.Cells[9].Text != null)
{
try
{
double price = double.Parse(e.Row.Cells[8].Text);
double num = double.Parse(e.Row.Cells[9].Text);
e.Row.Cells[10].Text = string.Format("{0:c}", num * price);
e.Row.Cells[8].Text = string.Format("{0:c}", price);
GridView1.Visible = true;
}
catch (Exception)
{
// lbldatastate.Text = "没有相关数据";
}
}
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[8].Text != null && e.Row.Cells[9].Text != null)
{
try
{
double price = double.Parse(e.Row.Cells[8].Text);
double num = double.Parse(e.Row.Cells[9].Text);
e.Row.Cells[10].Text = string.Format("{0:c}", num * price);
e.Row.Cells[8].Text = string.Format("{0:c}", price);
GridView1.Visible = true;
}
catch (Exception)
{
// lbldatastate.Text = "没有相关数据";
}
}
}
}
本文介绍了一个使用 C# 在 GridView 控件中动态计算并显示扩展价格的方法。通过监听 GridView 的 RowDataBound 事件,在每一行加载完毕后进行价格计算,并更新对应单元格的内容。
1156

被折叠的 条评论
为什么被折叠?



