C# – Hide a gridView row in asp.net

asp.netc++

I am creating a gridView that allows adding new rows by adding the controls necessary for the insert into the FooterTemplate, but when the ObjectDataSource has no records, I add a dummy row as the FooterTemplate is only displayed when there is data.

How can I hide this dummy row? I have tried setting e.row.visible = false on RowDataBound but the row is still visible.

Best Solution

You could handle the gridview's databound event and hide the dummy row. (Don't forget to assign the event property in the aspx code):

protected void GridView1_DataBound(object sender, EventArgs e)
    {
        if (GridView1.Rows.Count == 1)
            GridView1.Rows[0].Visible = false;
    }