4

I have Gridview control with 21 rows.Some of the rows have 0 values.My requirement is to set background color(consist 0 values Rows) as well as hide the values(means 0's).I can able to set background color.But the thing is,I am not able to hide row values.I have written this line of code, gridSellIn.Rows[0].Visible = false; .Total row is hiding.Make sure i have to show rows back ground color without values.Is this possible in asp.net.enter image description here

2
  • You want to show the row, but hide the values? Commented Feb 20, 2013 at 10:53
  • Absalutely.Because that row has back ground color.I have not mentioned color in image Commented Feb 20, 2013 at 11:19

3 Answers 3

4

In the grid RowDataBound event:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (...){
            //hide controls
            foreach (Control c in e.Row.Controls)
            {
                 c.Visible=false;
            }
            //change color
            e.Row.Style.Add("background-color","red");
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

1

In GridView1_RowDataBound event do the following with rows in which you want no values.

    for (int i = 0; i < e.Row.Cells.Count; i++)
        {
             e.Row.Cells[i].Text = "";
        }

1 Comment

Thanks for ur reply.but this code is not fulfill my requirement.please read again and see image.please help
0

You could do this is the DataBinding Event.

protected void GRIDVIEW_DataBinding(object sender, EventArgs e)
{
   foreach(GridViewRow grv in GRIDVIEW.Rows)
   {
     grv.Visible = (Condition_to_check_if_value_loaded_is_zero);
   }
}

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.