Konrad
Konrad

Reputation: 716

ASP DetailsView, conditionally hide show controls and row?

I conditionally hide/show panels in a DetailsView... I want to also hide/show the DetailsView row/field that the panel is contained in because it is currently displaying empty rows when the panels are hidden?

ASCX:

<asp:DetailsView>
<asp:TemplateField>
  <ItemTemplate>
    <asp:panel runat="server" ID="pnlHideShow" OnInit="OnInit_Panel">  
...

CodeBehind:

protected void OnInit_Panel(object sender, EventArgs e)
{
  Panel pnl = (Panel) sender;
  pnl.Visible = false;

  switch (pnl.ID)
  {
    default:
      break;
    case "pnlHideShow":
      pnl.Visible = (some condition); 
    //How to hide/show DetailsView item containing this panel? 
    break;
    ...
  }
  ...
}

Hope I am not a candidate for "worse-than-failure" ;)

Upvotes: 2

Views: 2992

Answers (1)

davewasthere
davewasthere

Reputation: 3018

Something like:

pnl.Visible = (some condition);
pnl.Parent.Visible = true;  // you may have to go pnl.Parent.Parent.Parent.Visible... try stepping through debug

Upvotes: 4

Related Questions