Tuesday, 6 March 2012

Customizing color of the cell as per the value/condition in a Paged DataGrid


 private void GetData()
    {
        dgParticipantList.DataSource = dataAccess.GetAllParticipants();
        dgParticipantList.DataBind();

        int pageCount = dgParticipantList.PageCount;

        for (int pageno = 1; pageno <= pageCount; pageno++)
        {
          int rowCount = dgParticipantList.Items.Count;
          for (int row = 0; row < rowCount; row++)
          {
            Literal status = dgParticipantList.Items[row].
                                   FindControl("litStatus"as Literal;

                if (status != null && status.Text.Equals("Selected"))
                {
                  dgParticipantList.Items[row].Cells[4].BackColor = Color.Green;
                  dgParticipantList.Items[row].Cells[4].ForeColor = Color.White;
                }

                else if (status != null && status.Text.Equals("Not Selected"))
                {
                  dgParticipantList.Items[row].Cells[4].BackColor = Color.Red;
                  dgParticipantList.Items[row].Cells[4].ForeColor = Color.White;
                }
            }
        }
    }

No comments:

Post a Comment