2

我有条件地在 DetailsView 中隐藏/显示面板...我还想隐藏/显示面板所在的 DetailsView 行/字段,因为当面板隐藏时它当前显示空行?

ASCX:

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

代码隐藏:

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

希望我不是“比失败更糟糕”的候选人;)

4

1 回答 1

4

就像是:

pnl.Visible = (some condition);
pnl.Parent.Visible = true;  // you may have to go pnl.Parent.Parent.Parent.Visible... try stepping through debug
于 2009-08-18T22:35:13.807 回答