可以';在具有Gridview事件的formview编辑模式中找不到面板控件
本文关键字:模式 编辑 formview 找不到 控件 事件 Gridview 可以 | 更新日期: 2023-09-27 18:22:37
我有一个面板可见=false。我有一个逻辑,如果满足条件,应该使面板可见。我找不到面板,我猜是因为看不见。也许我会尝试另一个活动,看看是否应该让面板在那里可见。像Databound事件一样?
更新****************根据以下关于使用显示器的评论:无非常好的建议。我确信这会解决我的问题。然而,在做了几件事之后,我甚至无法获得面板style="display:none"来隐藏面板。我知道我在编辑的正确面板上,因为我更改了里面的文本。
我做了几件事,比如禁用视图状态,在代码前面板中对样式进行硬编码,在itemcommand事件的顶部添加.attribute("style",block),在testPanel中认为我有东西以某种方式覆盖了可见性。。。。
更新#2***************我完全被难住了。。。这一切都应该奏效。。。所以,我做了一些进一步的谷歌搜索。现在我可能遗漏了一些重要信息,却不知道这些信息很重要。-我有一个网格视图-下表由选定的索引事件生成-我试着从下面的帖子中实现,但没有成功我无法更改控制';s在C#代码上的可见性
测试结果:-编辑命令正确启动-我删除了除此之外的任何控件-更新面板外部的面板可以更改-我将更新面板"UpdateMode"更改为Conditional,以确保没有其他内容被覆盖尽管我知道这个面板只存在于这一点,因为我刚刚添加了它。
那么,这是不是与网格视图有关?我把它添加到下面
.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>
State:<asp:Label ID="lblSourceState" runat="server" Text='<%# Eval("StateCode") %>'></asp:Label>
Country:<asp:Label ID="lblSourceCountry" runat="server" Text='<%# Eval("CountryName") %>'></asp:Label> <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;
}
}
}
表单视图上应该有一个触发编辑/更新的按钮。检查其属性是否为CommandName="Edit"。
尝试100%工作并测试:
即使您设置了Visible="false"
或Visible="true"
或
Style="display: none"
无关紧要您肯定会从FormView's
行获得面板使用这个
FormViewRow myFormRow = fvWasteCollected.Row;
Panel pnlOtherContractor1 = (Panel)myFormRow.FindControl("pnlOtherContractor");
注意:你在我的电脑上的问题很好。我建议你设置断点,并在fvWasteCollected_ItemCommand
事件上检查每个控件是否为null或myFormRow
是否为null。
MSDN REFERENCE
已解决。表单在生命周期中太早。在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;
}
}
}