62,041
社区成员
发帖
与我相关
我的任务
分享
<asp:GridView ID="Gv" runat="server" OnRowDataBound="Gv_RowDataBound" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="id" />
<asp:TemplateField>
<ItemTemplate>
<%# Eval("price") %>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button" ShowDeleteButton="true" />
</Columns>
</asp:GridView>
protected void Gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
decimal price = 0;
if (e.Row.RowType == DataControlRowType.DataRow)
{
/*注意下面这句有错,text出来是空值。转换就报错,但我始终不怎么明白这什么用了TemplateField就
不能通过cells[index]来访问了,如果换成这样:
(System.Web.UI.DataBoundLiteralControl)Gv.Rows[i].Cells[2].Controls[0]).Text就可以
正常访问到再者这样也可以:
price=(decimal)DataBinder.Eval(e.Row.DataItem,"price");也可以访问到, GOOGLE半天没有结果 不知道是什么原因,知道的吼吼。 感谢*/
price = Convert.ToDecimal(e.Row.Cells[1].Text);
if (price < 45)
e.Row.BackColor = System.Drawing.Color.Yellow;
}
}