1

在杂志上显示订阅价格时,我在页面上看到:

价格 | 订阅长度

69.95 | 12

69.95 | 24

24 个月的订阅应该是 12 个月(139.9)的两倍,但我还没有在数据库中实现它,它已经构建并在所有其他领域成功使用。

我想出了一个简单的公式来解决它,但我不知道把它放在哪里!

我使用 sqldatasource 在boundviews 中的gridview 中显示表格以定义要显示的内容

我在哪里放这个,应该怎么写?

/* sub 等于列子长度除以 6 再除以 2,所以 12=1 或 24=2 */

子=子长度/6/2

/* price=column price 乘以 sub,sub=1 没有变化,sub=2 然后加倍 */

价格=价格*子

4

2 回答 2

1

You can do it this way

<asp:GridView runat="server">
<Columns>
   <asp:BoundField DataField="Price" HeaderText="Price" />
   <asp:BoundField DataField="Months" HeaderText="Subscription Length" />

   <asp:TemplateField>
   <ItemTemplate>
      <%# (Convert.ToDecimal(Eval("Price")) * Convert.ToInt32(Eval("Months")) / 12) %>
   </ItemTemplate>
   </asp:TemplateField>
</Columns>
</asp:GridView>

Or this way

protected void Grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
   decimal Price = Convert.ToDecimal(e.Row.Cells[0].Text);
   int months = Convert.Int32(e.Row.Cells[1].Text);

   e.Row.Cells[0].Text = Price * (months / 12);
}
于 2012-11-10T05:56:29.233 回答
0

对于此类问题,您必须使用 GridView 的 onRowDatabound 事件。把你的逻辑代码放在那个事件中,一切都会如你所愿,只要确保你做的是正确的事情......

于 2012-11-10T03:20:59.100 回答