Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hide empty row in gridview

Tags:

c#

sql

I want to hide empty row in one particular column. I tried to but negative. 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;
        }
    }
}
like image 245
Abdujalil Chuliev Avatar asked Sep 04 '26 04:09

Abdujalil Chuliev


1 Answers

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 of foreach to iterate all the rows except last row which is empty.

like image 62
Vicky S Avatar answered Sep 05 '26 16:09

Vicky S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!