Hi
I don't know if this question is related to this thread, but I have a
perplexing problem. I am trying to reference a panel inside a
formview. I have code in the page load that looks like this:
If Not Page.IsPostBack Then
FormView1.ChangeMode(FormViewMode.Edit)
Dim multiDeptInt As Int32 = [some external condition that evaluates to
an int]
Dim multiDeptPnl2 as Panel =
CType(articleFormView.FindControl("pnlMultidept2") , Panel)
If multiDeptInt < 2 Then 'single
multiDeptPnl2.Visible = False
Else
multiDeptPnl2.Visible = True
End If
articleFormView.ChangeMode(FormViewMode.ReadOnly)
Dim multiDeptPnl1 as Panel = CType(tc.FindControl("pnlMultidept1"),
Panel)
If multiDeptInt < 2 Then 'single
multiDeptPnl1.Visible = False
Else
multiDeptPnl1.Visible = True
End If
End If
pnlMultidept2 is a control that exists only in the EditItemTemplate of
the formview; pnlMultiDept1 exists only in the ItemTemplate. And as I
mentioned above, the multiDeptInt flag is set externally.
The problem is this: the code has no trouble finding the pnlMultiDept2,
but it can't find the pnlMultiDept1 -- the code crashes on the
subsequent call to set the multDeptPnl1.Visible attribute.
Is there something fundamentally different between the ItemTemplate and
the EditItemTemplate where you have to control the behavior of
contained controls differently? Or maybe the ChangeMode isn't
happening?
I tried your advice of referencing the panel as contained by a table
cell instead of by the formview (although again, i don't understand why
it would be different for itemtemplate than for edititemtemplate):
If Not Page.IsPostBack Then
....
articleFormView.ChangeMode(FormViewMode.ReadOnly)
Dim fr as FormViewRow = Ctype(articleFormView.Controls(0).Controls(1),
FormViewRow)
Dim tc as TableCell = fr.Cells(0)
Dim multiDeptPnl1 as Panel = CType(tc.FindControl("pnlMultidept1"),
Panel)
If multiDeptInt < 2 Then 'single
multiDeptPnl1.Visible = False
Else
multiDeptPnl1.Visible = True
End If
End If
but it didn't make any difference.
TIA.
-- Ned Balzer
Luke Zhang [MSFT] wrote:
Hell Andrew,
The child controls of a Form View is not the controls we put in its item
template, it is first a "ChildTable", then some "FormViewRow", and then
"TableCell". The panel control is child control of "TableCell". please
refer following code:
FormViewRow fr = (FormViewRow)FormView1.Controls[0].Controls[1];
TableCell tc = fr.Cells[0];
foreach (System.Web.UI.Control c in tc.Controls)
Response.Write(c.ToString()+"<br>" );
Sincerely,
Luke Zhang
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.