找不到内部进行的GridView事件FormView的编辑模式控制面板 [英] Can't find panel control inside formview Edit mode with Gridview event
问题描述
我有一个面板可见=假。我有逻辑,应该使面板可见,如果条件得到满足。
我无法找到面板我猜这是因为它是不可见的。也许我会尝试另一个事件,看看我应该使面板可见那里。像数据绑定的事件吗?
更新****************
每在注释下使用显示:无
很好的建议。我想肯定有人会解决我的问题。做几件事情后,但是,我不能让面板风格=显示:无,甚至隐藏面板。我知道我在编辑正确的面板,因为我改变了文本中。
我已经做了几件事情,如在ItemCommand事件的顶视图状态禁用硬codeD在code前面板风格,add.attribute(风格,块),在放一パ思考我有莫名其妙的东西覆盖的知名度....
更新#2 ***************
我完全难倒......这一切都应该工作......于是,我做了一些进一步的谷歌搜索。现在,我可能已经离开了一些重要的信息,不知道它重要的。
- 我有一个网格视图
- 下面的表格是由selectedIndex事件产生
- 我试着从以下职位,但没有喜悦实施
<一href=\"http://stackoverflow.com/questions/3862397/i-cannot-change-controls-visibility-on-c-sharp-$c$c\">I不能改变C#code 控制的知名度
测试结果:
- 编辑命令是越来越正常解雇
- 我删除比这个地区之外的任何控件
- 外UpdatePanel的一个面板可以改变
- 我改变了更新面板的UpdateMode为条件,以确保没有别的覆盖
尽管我知道这个面板只存在在这一点上,因为我只是说了。
那么,这事与GridView的?这是我补充它在下面
的.aspx
&LT; ASP:面板ID =pnlCollectionEventAll=服务器&GT;
&LT; ASP:GridView控件ID =gvCollectionEventDetail=服务器SkinID =annualReportGridviewAllowSorting =真
的AutoGenerateColumns =FALSE的cellpadding =4的DataSourceID =odsMRWCollectionDetailByReportIdEnableSortingAndPagingCallbacks =假
的DataKeyNames =MRWCollectionReportDetailId前景色=#333333网格=垂直WIDTH =720像素
ShowFooter =真OnRowDataBound =gvCollectionEventDetail_RowDataBoundOnSelectedIndexChanged =gvCollectionEventDetail_SelectedIndexChanged&GT;
&LT;柱体和GT;
&LT; ASP:CommandField中按钮类型=按钮ShowSelectButton =真SelectText =选择
ItemStyle-HorizontalAlign =左ControlStyle-前景色=#1A3B69/&GT;
&LT; ASP:的TemplateField的HeaderText =处理方法SORTEX pression =DisposalMethod code
FooterStyle-HorizontalAlign =左HeaderStyle-HorizontalAlign =左&GT;
&LT;&ItemTemplate中GT;
&LT; ASP:标签ID =lblDisposalMethod=服务器文本='&LT;%#的eval(DisposalMethod code)%&GT;'&GT;&LT; / ASP:标签&gt;
&LT; / ItemTemplate中&GT;
&LT; ItemStyle HorizontalAlign =左/&GT;
&LT; / ASP:的TemplateField&GT;
&LT; ASP:的TemplateField的HeaderText =数量处置(LBS)FooterStyle-HorizontalAlign =左
HeaderStyle-HorizontalAlign =左&GT;
&LT;&ItemTemplate中GT;
&LT; ASP:标签ID =lblWasteQty=服务器文本='&LT;%#的eval(WasteQuantity)%&GT;'&GT;&LT; / ASP:标签&gt;
&LT; / ItemTemplate中&GT;
&LT; ItemStyle HorizontalAlign =左/&GT;
&LT; / ASP:的TemplateField&GT;
&LT; ASP:的TemplateField的HeaderText =承包人FooterStyle-HorizontalAlign =左
HeaderStyle-HorizontalAlign =左&GT;
&LT;&ItemTemplate中GT;
县:&LT; ASP:标签ID =lblSourceCounty=服务器文本='&LT;%#的eval(CountyName)%&GT;'&GT;&LT; / ASP:标签&gt;&安培; NBSP;
状态:其中,ASP:标签ID =lblSourceState=服务器文本='&LT;%#的eval(国家code)%&GT;'&GT;&LT; / ASP:标签&gt;&安培; NBSP ;
国家:&LT; ASP:标签ID =lblSourceCountry=服务器文本='&LT;%#的eval(国家或地区名称)%&GT;'&GT;&LT; / ASP:标签&gt;&安培; NBSP;&LT; BR /&GT;
&LT; / ItemTemplate中&GT;
&LT; ItemStyle HorizontalAlign =左/&GT;
&LT; / ASP:的TemplateField&GT;
&LT; /专栏&GT;
&LT; EmptyDataTemplate&GT;
没有MRW收集细节已经进入了这份报告。
&LT; / EmptyDataTemplate&GT;
&LT; / ASP:GridView的&GT;
&LT; / ASP:面板&gt;
&LT; ASP:按钮的ID =btn_addWasteCollectedRecord=服务器文本=添加收集记录一个新的废物的OnClick =btn_addWasteCollectedRecord_Click/&GT;
&LT; ASP:按钮的ID =btn_addWasteCollectedRecordDone=服务器文本=完成添加垃圾收集记录可见=假的OnClick =btn_addWasteCollectedRecordDone_Click/&GT;
&LT; BR /&GT;&LT; BR /&GT;
&LT; ASP:FormView控件ID =fvWasteCollected=服务器SkinID =annualReportFormviewViewStateMode =已禁用
的HeaderText =选择废物收集详细信息的DataKeyNames =MRWCollectionReportDetailIdDefaultMode =插入
的DataSourceID =odsMRWWasteCollectedDetailOnDataBound =fvWasteCollected_DataBound
OnItemCommand =fvWasteCollected_ItemCommandOnItemInserted =fvWasteCollected_ItemInserted
OnItemUpdated =fvWasteCollected_ItemUpdatedOnItemDeleted =fvWasteCollected_ItemDeleted&GT;
&LT;&EditItemTemplate的GT;
&LT;表类=detailstable&GT;
&LT; ASP:面板ID =pnlOtherContractor=服务器可见=假&GT;
&所述; TR&GT;
百分位&GT;&LT; /第i
&LT; TD align =left&GT;
等等等等
&LT; / TD&GT;
&LT; / TR&GT;
&LT; / ASP:面板&gt;
&LT; /表&gt;
&LT; / EditItemTemplate中&GT;
aspx.cs
保护无效gvCollectionEventDetail_SelectedIndexChanged(对象发件人,EventArgs的发送)
{
fvWasteCollected.ChangeMode(FormViewMode.ReadOnly);
fvWasteCollected.DataBind();
pnlMWRCOllectionForm.Visible =真; //隐藏堆肥产生附加的LinkButton
btn_addWasteCollectedRecord.Visible = FALSE;
btn_addWasteCollectedRecordDone.Visible = FALSE; //隐藏编辑删除fvFeedstockDetail按钮,如果年度报告已经提交
//和登录用户没有ECY授权工作人员编辑报告##################################
标签myLblSubmitDate1 =(标签)fvRptHeader.FindControl(lblSubmitDate); LinkButton的lbtnWasteCollectedEdit =(LinkButton的)fvWasteCollected.FindControl(lbtnWasteCollectedEdit);
LinkButton的lbtnWasteCollectedDelete =(LinkButton的)fvWasteCollected.FindControl(lbtnWasteCollectedDelete); 如果(!String.IsNullOrEmpty(myLblSubmitDate1.Text.Trim()))
{
lbtnWasteCollectedEdit.Visible = FALSE;
lbtnWasteCollectedDelete.Visible = FALSE;
btn_addWasteCollectedRecord.Visible = FALSE;
}
}
保护无效fvWasteCollected_ItemCommand(对象发件人,FormViewCommandEventArgs E)
{
如果(e.CommandName.Equals(编辑))
{ ValidationSummaryWasteDetail.ValidationGroup =WasteReceivedDetail;
fvWasteCollected.ChangeMode(FormViewMode.Edit);
gvCollectionEventDetail.Columns [0] =。可见假的;
DataRowView的rowView =(DataRowView的)fvWasteCollected.DataItem;
DropDownList的DDL =(DropDownList的)fvWasteCollected.FindControl(ddl_MRWContractor);
//试图面板pnlOtherContractor =(面板)fvWasteCollected.FindControl(pnlOtherContractor);
FormViewRow myFormRow = fvWasteCollected.Row;
面板pnlOtherContractor =(面板)myFormRow.FindControl(pnlOtherContractor); VAR s_contractorId = rowView [MRWContractorId]的ToString()。
如果(s_contractorId ==0)
{
pnlOtherContractor.Visible =真;
}
}
}
解决它。该形式是在生命周期为时尚早。在数据绑定事件,检查如果CURRENTMODE是编辑,然后我做了我的数据检查
保护无效fvWasteCollected_DataBound(对象发件人,EventArgs的发送)
{
FormView控件FormView控件= fvWasteCollected;
FormViewRow排= fvWasteCollected.Row;
DataRowView的rowview =(DataRowView的)fvWasteCollected.DataItem;
面板pnlOtherContractor =(面板)fvWasteCollected.FindControl(pnlOtherContractor2); 如果(fvWasteCollected.CurrentMode == FormViewMode.Edit)
{
VAR s_contractorId = rowview [MRWContractorId]的ToString()。
如果(s_contractorId ==0)
{
pnlOtherContractor.Visible =真;
}
其他
{
pnlOtherContractor.Visible = FALSE;
}
} }
I have a Panel visible=false. I have logic that should make the panel viewable if condition is met. I can't locate the the panel I'm guessing it's because it's not visible. Maybe I'll try on another event and see if I should make the panel visible there. Like the Databound event?
UPDATE**************** Per the comment below on using display:none excellent suggestion. I thought for sure it was going to fix my issue. However after doing several things, I cannot get the panel style="display:none" to even hide the panel. I know I am in the correct panel on edit as I changed text inside.
I've done several things such as disabled viewstate, hardcoded the style in the code front panel, add.attribute("style",block) at the top of the itemcommand event, put in a testPanel thinking I had something overwriting the visibility somehow....
UPDATE #2*************** I'm totally stumped... This all SHOULD work... So, I did some further googling. Now I may have left out some important information not knowing that it mattered. - I have a grid view - The form below is produced by the selectedindex event - I tried to implement from the following post but no joy I cannot change control's visibility on C# code
TESTING RESULTS: - The Edit Command is getting fired properly - I removed any controls other than this pacific one - A panel OUTSIDE the updatepanel can be changed - I changed the Update Panel "UpdateMode" to Conditional to make sure nothing else was overwriting even though I know this panel only exists at this point since I just added it.
So is it something with the gridview? Which I added it in below
.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;
}
}
}
Resolved it. The form was too early in the lifecycle. in the Databound event, checked if the currentMode was in edit, then I did my checks on the data
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;
}
}
}
这篇关于找不到内部进行的GridView事件FormView的编辑模式控制面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!