Search code examples
asp.netgridviewwebformsdropdownrowdatabound

How to test if a row of gridview is empty asp.net


I have a empty grid view at the page load . In the RowDataBound event I add a dropdownlist to the last cell The problem is that the ddl is shown at the page load. I want to hide it if the cells of row are empty

protected void grw_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DropDownList ddl = e.Row.FindControl("ddlAccepted") as DropDownList;
            if (null != ddl)
            {
                string acceptedKey = (e.Row.FindControl("lblAccepted") as Label).Text;
                string acceptedValue = "";
                if (acceptedKey == "True")
                {
                    acceptedValue = "Oui";
                }
                else if (acceptedKey == "False")
                {
                    acceptedValue = "Non";
                }

                ddl.Items.Add(new ListItem("Non", "False"));
                ddl.Items.Add(new ListItem("Oui", "True"));

                ddl.SelectedValue = acceptedValue;
            }


        }

    }

enter image description here Thank you.


Solution

  • I found the solution The empty cells have the Text equals to   So I add this line and it works

    if (e.Row.Cells[0].Text != " ")