【问题标题】:Can't find panel control inside formview Edit mode with Gridview event在带有 Gridview 事件的 formview 编辑模式中找不到面板控件
【发布时间】:2014-11-14 09:17:54
【问题描述】:

我有一个面板 visible=false。如果满足条件,我有逻辑应该使面板可见。 我找不到面板,我猜是因为它不可见。也许我会尝试另一个活动,看看是否应该让面板在那里可见。喜欢 Databound 事件?

更新**************** 根据下面关于使用 display:none 的评论 很好的建议。我确信它会解决我的问题。但是,在做了几件事之后,我无法让面板 style="display:none" 甚至隐藏面板。我知道我在正确的编辑面板中,因为我更改了里面的文本。

我已经做了几件事,例如禁用视图状态,在代码前面板中硬编码样式,在 itemcommand 事件顶部添加.attribute("style",block),放入 testPanel 以为我有一些内容被覆盖不知何故的能见度......

更新#2*************** 我完全被难住了......这一切都应该工作......所以,我做了一些进一步的谷歌搜索。现在我可能遗漏了一些重要的信息,但我并不知道这很重要。 - 我有一个网格视图 - 下面的表格是由 selectedindex 事件产生的 - 我试图从下面的帖子中实现,但没有喜悦 I cannot change control's visibility on C# code

测试结果: - 编辑命令被正确触发 - 我删除了除此太平洋之外的任何控件 - 可以更改更新面板之外的面板 - 我将更新面板“UpdateMode”更改为 Conditional 以确保没有其他内容被覆盖 即使我知道这个面板只存在于这一点上,因为我刚刚添加了它。

那么它与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;
            }
        }
    }

【问题讨论】:

  • 而不是 visible=truefalse 将 Panel 设置为 display:nonedisplay:block
  • 更新我上面的帖子。
  • 嘿 Ganesh,我对我的原始帖子进行了编辑。我仍在研究更多,由于 gridview 事件,这似乎是一个问题。有什么见解吗?

标签: c# asp.net webforms


【解决方案1】:

应该有一个按钮可以触发表单视图上的编辑/更新。检查它是否有 CommandName="Edit" 作为它的属性。

【讨论】:

    【解决方案2】:

    试试这个 100% 的工作和测试:

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

     Style="display: none" 
    

    没关系您肯定会从FormView's Row 获得面板 使用这个

     FormViewRow myFormRow = fvWasteCollected.Row;
     Panel pnlOtherContractor1 = (Panel)myFormRow.FindControl("pnlOtherContractor");
    

    注意:您的问题在我的 PC 上工作正常。我建议您设置断点并检查每个控件是否为空或 myFormRow 是否为空 fvWasteCollected_ItemCommand 事件。

    MSDN REFERENCE

    【讨论】:

      【解决方案3】:

      解决了。该表单在生命周期中为时过早。在 Databound 事件中,检查 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;
                  }
              }
      
          }
      

      【讨论】:

        猜你喜欢
        • 2014-03-02
        • 2011-08-31
        • 2010-11-08
        • 2013-01-13
        • 2013-09-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多