2014-09-19 33 views
0

我有一個Panel可見= false。我有邏輯,應該使面板可見如果條件得到滿足。 我找不到面板我猜這是因爲它不可見。也許我會嘗試另一個事件,看看我是否應該讓面板可見。像Databound事件?找不到Gridview事件中的formview編輯模式的面板控制

更新**************** 根據以下關於使用顯示器的註釋:無 極好的建議。我確信它會解決我的問題。然而,在做了幾件事情之後,我無法獲得面板樣式=「display:none」甚至隱藏面板。我知道我在編輯的正確面板上,因爲我在裏面改變了文字。

我已經做了幾件事情,比如禁用viewstate,在代碼前面板中對代碼樣式進行硬編碼,在itemcommand事件的頂部添加屬性(「樣式」,塊),放入testPanel中,以某種方式覆蓋能見度....

UPDATE#2 *************** 我完全難住...這一切應該工作...所以,我做了一些進一步的谷歌搜索。現在我可能已經遺漏了一些不知道它重要的重要信息。 - 我有一個網格視圖 - 下面是由selectedIndex事件 生產的形式 - 我試着從下面的帖子,但沒有喜悅 I cannot change control's visibility on C# code

測試結果來實現: - edit命令是越來越正常解僱 - 我刪除了這個太平洋之外的任何控件 - 面板外面的更新面板可以更改 - 我更改了更新面板「更新模式」以有條件地確保沒有其他東西被覆蓋 即使我知道此面板只存在於此因爲我剛添加它。

所以這是什麼與gridview?這是我加入它下面

的.aspx

<asp:Panel ID="pnlCollectionEventAll" runat="server"> 
     <asp:GridView ID="gvCollectionEventDetail" runat="server" SkinID="annualReportGridview" AllowSorting="True" 
     AutoGenerateColumns="False" CellPadding="4" DataSourceID="odsMRWCollectionDetailByReportId" EnableSortingAndPagingCallbacks="false" 
     DataKeyNames="MRWCollectionReportDetailId" ForeColor="#333333" GridLines="Vertical" Width="720px" 
     ShowFooter="True" OnRowDataBound="gvCollectionEventDetail_RowDataBound" OnSelectedIndexChanged="gvCollectionEventDetail_SelectedIndexChanged"> 
      <Columns> 
        <asp:CommandField ButtonType="button" ShowSelectButton="true" SelectText="Select" 
             ItemStyle-HorizontalAlign="Left" ControlStyle-ForeColor="#1A3B69" /> 
        <asp:TemplateField HeaderText="Disposal Method" SortExpression="DisposalMethodCode" 
             FooterStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"> 
        <ItemTemplate> 
           <asp:Label ID="lblDisposalMethod" runat="server" Text='<%# Eval("DisposalMethodCode") %>'></asp:Label> 
        </ItemTemplate> 
        <ItemStyle HorizontalAlign="Left" /> 
        </asp:TemplateField> 
        <asp:TemplateField HeaderText="Qty disposed (lbs)" FooterStyle-HorizontalAlign="Left" 
             HeaderStyle-HorizontalAlign="Left"> 
        <ItemTemplate> 
         <asp:Label ID="lblWasteQty" runat="server" Text='<%# Eval("WasteQuantity") %>'></asp:Label> 
        </ItemTemplate> 
        <ItemStyle HorizontalAlign="Left" /> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="Contractor" FooterStyle-HorizontalAlign="Left" 
             HeaderStyle-HorizontalAlign="Left"> 
      <ItemTemplate> 
        County:<asp:Label ID="lblSourceCounty" runat="server" Text='<%# Eval("CountyName") %>'></asp:Label>&nbsp; 
        State:<asp:Label ID="lblSourceState" runat="server" Text='<%# Eval("StateCode") %>'></asp:Label>&nbsp; 
        Country:<asp:Label ID="lblSourceCountry" runat="server" Text='<%# Eval("CountryName") %>'></asp:Label>&nbsp;<br /> 
      </ItemTemplate> 
      <ItemStyle HorizontalAlign="Left" /> 
      </asp:TemplateField> 
      </Columns> 
      <EmptyDataTemplate> 
       No MRW Collection details have been entered for this report. 
      </EmptyDataTemplate> 
      </asp:GridView> 
     </asp:Panel> 
     <asp:Button ID="btn_addWasteCollectedRecord" runat="server" Text="Add a New Waste Collected Record" OnClick="btn_addWasteCollectedRecord_Click" /> 
     <asp:Button ID="btn_addWasteCollectedRecordDone" runat="server" Text="Done Adding Waste Collected Records" Visible="false" OnClick="btn_addWasteCollectedRecordDone_Click" /> 
         <br /><br /> 
    <asp:FormView ID="fvWasteCollected" runat="server" SkinID="annualReportFormview" ViewStateMode="Disabled" 
      HeaderText="Selected Waste Collected Detail" DataKeyNames="MRWCollectionReportDetailId" DefaultMode="Insert" 
      DataSourceID="odsMRWWasteCollectedDetail" OnDataBound="fvWasteCollected_DataBound" 
      OnItemCommand="fvWasteCollected_ItemCommand" OnItemInserted="fvWasteCollected_ItemInserted" 
      OnItemUpdated="fvWasteCollected_ItemUpdated" OnItemDeleted="fvWasteCollected_ItemDeleted"> 
      <EditItemTemplate> 
       <table class="detailstable"> 
        <asp:Panel ID="pnlOtherContractor" runat="server" Visible="false"> 
          <tr> 
           <th></th> 
            <td align="left"> 
             Blah Blah 
            </td> 
          </tr> 
        </asp:Panel> 
       </table> 
    </EditItemTemplate> 

aspx.cs

protected void gvCollectionEventDetail_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     fvWasteCollected.ChangeMode(FormViewMode.ReadOnly); 
     fvWasteCollected.DataBind(); 
     pnlMWRCOllectionForm.Visible = true; 

     //hide the compost produced add linkbutton 
     btn_addWasteCollectedRecord.Visible = false; 
     btn_addWasteCollectedRecordDone.Visible = false; 

     // hide the edit delete button on fvFeedstockDetail if the annual report already submitted 
     //and the logon user is not ecy staff authorized to edit report ################################## 
     Label myLblSubmitDate1 = (Label)fvRptHeader.FindControl("lblSubmitDate"); 

     LinkButton lbtnWasteCollectedEdit = (LinkButton)fvWasteCollected.FindControl("lbtnWasteCollectedEdit"); 
     LinkButton lbtnWasteCollectedDelete = (LinkButton)fvWasteCollected.FindControl("lbtnWasteCollectedDelete"); 

     if (!String.IsNullOrEmpty(myLblSubmitDate1.Text.Trim())) 
     { 
      lbtnWasteCollectedEdit.Visible = false; 
      lbtnWasteCollectedDelete.Visible = false; 
      btn_addWasteCollectedRecord.Visible = false; 
     } 
    } 
protected void fvWasteCollected_ItemCommand(object sender, FormViewCommandEventArgs e) 
    { 
     if (e.CommandName.Equals("Edit")) 
     { 

      ValidationSummaryWasteDetail.ValidationGroup = "WasteReceivedDetail"; 
      fvWasteCollected.ChangeMode(FormViewMode.Edit); 
      gvCollectionEventDetail.Columns[0].Visible = false; 
      DataRowView rowView = (DataRowView)fvWasteCollected.DataItem; 
      DropDownList ddl = (DropDownList)fvWasteCollected.FindControl("ddl_MRWContractor"); 
      //Tried Panel pnlOtherContractor = (Panel)fvWasteCollected.FindControl("pnlOtherContractor"); 
      FormViewRow myFormRow = fvWasteCollected.Row; 
      Panel pnlOtherContractor = (Panel)myFormRow.FindControl("pnlOtherContractor"); 

      var s_contractorId = rowView["MRWContractorId"].ToString(); 
      if (s_contractorId == "0") 
      { 
       pnlOtherContractor.Visible = true; 
      } 
     } 
    } 
+1

,而不是'可見= TRUE;或我的支票'FALSE'設置面板來顯示':none'和'顯示:塊' – 2014-09-19 18:35:13

+0

更新我的帖子上面。 – MSW 2014-09-19 20:44:57

+0

試試我發佈的內容 – 2014-09-20 20:07:13

回答

0

解決它。這種形式在生命週期中過早。在數據綁定事件,檢查如果CURRENTMODE是編輯,然後我做了數據

protected void fvWasteCollected_DataBound(object sender, EventArgs e) 
    { 
     FormView formview = fvWasteCollected; 
     FormViewRow row = fvWasteCollected.Row; 
     DataRowView rowview = (DataRowView)fvWasteCollected.DataItem; 
     Panel pnlOtherContractor = (Panel)fvWasteCollected.FindControl("pnlOtherContractor2"); 

     if (fvWasteCollected.CurrentMode == FormViewMode.Edit) 
     { 
      var s_contractorId = rowview["MRWContractorId"].ToString(); 
      if (s_contractorId == "0") 
      { 
       pnlOtherContractor.Visible = true; 
      } 
      else 
      { 
       pnlOtherContractor.Visible = false; 
      } 
     } 

    } 
0

應該有一個按鈕,觸發在表單視圖編輯/更新。檢查它是否具有CommandName =「Edit」作爲其屬性。

0

試試這個100%的工作和測試:

即使你設置Visible="false"Visible="true"

Style="display: none" 

並不重要你會使用這個

肯定獲得小組從 FormView's
FormViewRow myFormRow = fvWasteCollected.Row; 
Panel pnlOtherContractor1 = (Panel)myFormRow.FindControl("pnlOtherContractor"); 

否te:您的問題在我的電腦上工作Fine.I建議您設置斷點並檢查每個控件是否爲null或爲空或不在fvWasteCollected_ItemCommand事件。

MSDN REFERENCE

相關問題