Wednesday, April 24, 2019

GridView not returning all the rows in it, only returning Page 1 rows.

Hi,

I am trying to colour a row of a gridview based on the condition - If the first cell of the table matches today's date, than the entire row is coloured. However, I noticed that the Rows.Count only returns the specific page's rows. How do I get the code to retrieve all the rows of a gridview and then colour it.

protected void OnDataBound(object sender, EventArgs e) { GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal); TableHeaderCell cell = new TableHeaderCell(); cell.Text = "Details"; cell.ColumnSpan = 2; row.Controls.Add(cell); cell = new TableHeaderCell(); cell.ColumnSpan = 3; cell.Text = "Full Day"; cell.BackColor = System.Drawing.Color.Blue; cell.ForeColor = System.Drawing.Color.White; row.Controls.Add(cell); cell = new TableHeaderCell(); cell.ColumnSpan = 3; cell.Text = "Shift 1"; cell.BackColor = System.Drawing.Color.Yellow; cell.ForeColor = System.Drawing.Color.Black; row.Controls.Add(cell); cell = new TableHeaderCell(); cell.ColumnSpan = 3; cell.Text = "Shift 2"; cell.BackColor = System.Drawing.Color.Black; cell.ForeColor = System.Drawing.Color.White; row.Controls.Add(cell); //row.BackColor = ColorTranslator.FromHtml("#B0C4DE"); GridView1.HeaderRow.Parent.Controls.AddAt(0, row); ----This part needs help for(int row_index = 0; row_index < GridView1.Rows.Count; row_index++) { string rowsdate = GridView1.Rows[row_index].Cells[0].Text; if (rowsdate == DateTime.Now.ToString("dd/MM/yyyy")) { //GridView1.RowStyle.BackColor = System.Drawing.Color.Black; GridView1.Rows[row_index].Cells[0].BackColor = System.Drawing.Color.Black; } } } 
GridView not returning all the rows in it, only returning Page 1 rows. Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team