2009-03-30 7 views
2

Je cache/affiche les panneaux de façon conditionnelle dans un DétailsView ... Je veux également masquer/afficher la ligne/le champ DetailsView que contient le panneau car il affiche actuellement des lignes vides lorsque les panneaux sont cachés?ASP DetailsView, masquer conditionnellement afficher les contrôles et la rangée?

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; 
    ... 
    } 
    ... 
} 

espoir Je ne suis pas un candidat pour "worse-than-failure";)

Répondre

4

Quelque chose comme:

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

((TextBox) DetailsView1.FindControl (» txtComments ")). Parent.Parent.Visible a fonctionné pour moi :) – JumpingJezza

Questions connexes