0

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 just 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 ?

2 Answers 2

1

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!

Sign up to request clarification or add additional context in comments.

2 Comments

thanks the first bit works perfect for the second bit im evaluating th value on the fly similar to what iv show above. aslo how would i change the text on the last row so that it would be bold ?
to make the text bold: accessoriesGridView.Rows[r].Font.Bold = true;
1

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; 

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.