开发者

ASP.NET help with formatting gridview

开发者 https://www.devze.com 2023-03-14 13:25 出处:网络
im using a gridview to display data taken from a dataset which looks like NAME | GP| ORD_GP | EXP| TOTAL GP | TARGET

im using a gridview to display data taken from a dataset which looks like

NAME | GP   | ORD_GP | EXP   | TOTAL GP | TARGET
a      206     48      -239     15         1600
b      0       27       0        27        1520
TOTAL  206     75      -239     42         3120 

im using TemplateField like so but this can jus开发者_运维知识库t format values.

    <asp:TemplateField HeaderText="%" ItemStyle-BackColor="Yellow" >
        <ItemTemplate>
            <span class='<%# double.Parse(Eval("PERC_OF_TARGET").ToString()) >= 100 ? "PERC_MoreThan" : "PERC_LessThan"  %>'>
            <%# Eval("PERC_OF_TARGET")%> %
        </span>
    </ItemTemplate>
</asp:TemplateField>

however what I want to do is format the last row (TOTAL) so that the background colour is green.

also is there a way that I can evaluate each item and if it equals to 0 Do not display anything and just leave it blank ?


for making the last row of grid view green:

int r = GridView.Rows.Count;
r--;
GridView.Rows[r].BackColor = System.Drawing.Color.Green;

and to evaluate the value of each cell and make it blank if its 0:

for (int i = 0; i < dt.Rows.Count; i++)
{
    for (int j = 0; j < dataTable.Columns.Count; j++)
    {
        if (Convert.ToInt32(dt.Rows[i][j]) == 0)
        {
            dt.Rows[i][j] = "";
        }
    }
}

hope thats what you needed!


hello dear you can use the grid view prerender event to find the last row and change its background color.

protected void grdData_PreRender(object sender, EventArgs e)
{

    grdData.Rows[grdData.Rows.Count - 1].BackColor = System.Drawing.Color.Red; 

}
0

精彩评论

暂无评论...
验证码 换一张
取 消