Hide empty row in gridview

I want to hide a blank row in one column. I tried, but no. Below is my code:

protected void gvDb_DataBound(object sender, EventArgs e)
{
    foreach (GridViewRow rw in gvDb.Rows)
    {
        if ((string.IsNullOrEmpty(rw.Cells[1].Text) | (rw.Cells[1].Text == "")))
        {
            rw.Visible = false;
        }
    }
}

      

+3


source to share


1 answer


for (int i = 0; i < gvDb.RowCount - 1; i++)
{
    var row = gvDb.Rows[i];
    if (string.IsNullOrEmpty(Convert.ToString(row.Cells[1].Value)))
    {
        row.Visible = false;
    }
}

      



This will work, use for

instead foreach

to repeat all lines except the last line, which is empty.

+1


source







All Articles