Search code examples
c#asp.netuser-controlssqldatasourceauto-generate

Hide AutoGenerateRows from a User Control?


I have a User Control with a DetailsView that has the property AutoGenerateRows set to 'true'. My pages (asp.net and c# code), use a SQLDataSource for its data. Typically I want all rows to show up in my WebForm, however, occasionally I want to be able to hide specific ones. Is there any way to do this or do I have to hardcode every row I want and set autogeneraterows to false?

Help is appreciated! Thanks everyone!


Solution

  • Try this After Binding

     foreach (DetailsViewRow Row in MyDetailsView1.Rows)
            {
                if (Your Condition..)
                {
                    Row.Visible = false;
                }
            }
    

    you could do this for checking your value:

    foreach (DetailsViewRow Row in MyDetailsView1.Rows)
                {
                    if (Row.Cells[index of your column].Text=="")
                    {
                        Row.Visible = false;
                    }
                }