【发布时间】: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>
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;
}
}
}
【问题讨论】:
-
而不是
visible=true或false将 Panel 设置为display:none和display:block -
更新我上面的帖子。
-
嘿 Ganesh,我对我的原始帖子进行了编辑。我仍在研究更多,由于 gridview 事件,这似乎是一个问题。有什么见解吗?