这是一个两部分问题,即时处理数据集和网格视图。通过查询数据库填充数据集,然后完成一些计算并添加到数据集中。一旦完成所有计算,数据集就会绑定到网格视图。看起来像这样。如何在网格视图中绑定项目
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None" Width="100%" CssClass="tableText" >
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
<Columns>
<asp:BoundField DataField="INV_GP" HeaderText="INV GP" />
<asp:BoundField DataField="SORG_GP" HeaderText="SORD GP" />
<asp:BoundField DataField="SRTN_GP" HeaderText="SRTN GP" />
<asp:BoundField DataField="EXPEND" HeaderText="EXPEND" />
<asp:BoundField DataField="TARGET" HeaderText="TARGET" />
<asp:BoundField DataField="PERC_OF_TARGET" HeaderText="%" />
<asp:BoundField DataField="M_PERC" HeaderText="M%" />
<asp:BoundField DataField="100NEED" HeaderText="NEED FOR 100%" />
</Columns>
</asp:GridView>
这是我希望能够做到:
正如你可以看到列有%值,但该数据集只具有数量。如何在gridview中显示数字旁边的%?
我希望能够添加某种条件语句,以便能够以不同颜色显示文本。例如,在m%中,如果任何值小于50%,我希望文本显示为红色。
给这个人一条鱼,或教他钓鱼? – mikey 2011-06-16 15:02:11
@mikey:取决于他是多么饿...... :) – Town 2011-06-16 15:04:16
@Town我喜欢那个;) – mikey 2011-06-16 15:09:34