Hello Andrew,
From your description, you're putting a placeholder control in FromView's
EditTemplate, and you'll programmatically determine the placeholder's
Visibility according to another dropdownlist's selected item. However, you
found that the placeholder's visiblity doesn't be as expected when you try
perform updating on the Formview, correct?
As for this problem, I still have something need to confirm on your page:
1. Whether the dropdownlist is in FormView or ouside the Formview, but on
the same page.
2. How did you programmatically set the DropDownList's Visibilty and in
which event (page or FormView's) did you put the code
3. When you click update button(or postback the page to trigger FormView's
update command), the formView should return back to readonly mode after the
postback. When did you check the visibility? Do you mean you check in the
updating event(or any other event during the update comand postback)?
I've created a test page on my side based on my understanding. And I put
the programamtic visibility code(for the placeholder) in FormView's Load
event. You can refer to it and let me know if there is anything I missed.
===========aspx=================
<html xmlns="
http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp
ropDownList ID="DropDownList1" runat="server">
<asp:ListItem>aaa</asp:ListItem>
<asp:ListItem>bbb</asp:ListItem>
<asp:ListItem>ccc</asp:ListItem>
<asp:ListItem>ddd</asp:ListItem>
</asp
ropDownList><br />
<asp:FormView ID="FormView1" runat="server"
DataKeyNames="AddressTypeID" DataSourceID="SqlDataSource1"
OnItemCreated="FormView1_ItemCreated"
OnItemUpdating="FormView1_ItemUpdating" OnLoad="FormView1_Load"
OnModeChanged="FormView1_ModeChanged">
<EditItemTemplate>
AddressTypeID:
<asp:Label ID="AddressTypeIDLabel1" runat="server"
Text='<%# Eval("AddressTypeID") %>'></asp:Label><br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%#
Bind("Name") %>'></asp:TextBox><br />
<hr />
<asp
laceHolder ID="PlaceHolder1" runat="server">
<table>
<tr>
<td>
<asp:Label ID="lblResponseText"
runat="server">Response Text: </asp:Label></td>
<td>
<asp:TextBox ID="tbResponseText"
runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</td>
</tr>
</table>
</asp
laceHolder>
<br />
<hr />
<br />
<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update"
Text="Update"></asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%#
Bind("Name") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="InsertButton" runat="server"
CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
AddressTypeID:
<asp:Label ID="AddressTypeIDLabel" runat="server" Text='<%#
Eval("AddressTypeID") %>'></asp:Label><br />
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%#
Bind("Name") %>'></asp:Label><br />
<asp:LinkButton ID="EditButton" runat="server"
CausesValidation="False" CommandName="Edit"
Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:FormView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString %>"
SelectCommand="SELECT AddressTypeID, Name FROM
Person.AddressType" UpdateCommand="UPDATE Person.AddressType SET">
</asp:SqlDataSource>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>
=========code behind=============
public partial class FormViewPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void FormView1_ItemCreated(object sender, EventArgs e)
{
}
protected void FormView1_ModeChanged(object sender, EventArgs e)
{
}
protected void FormView1_Load(object sender, EventArgs e)
{
Response.Write("<br/>FormView1_Load+FormView1_CurrentMode: " +
FormView1.CurrentMode);
if (FormView1.CurrentMode == FormViewMode.Edit)
{
if (DropDownList1.SelectedValue == "ccc")
{
FormView1.FindControl("PlaceHolder1").Visible = true;
}
else
{
FormView1.FindControl("PlaceHolder1").Visible = false;
}
}
}
protected void FormView1_ItemUpdating(object sender,
FormViewUpdateEventArgs e)
{
Response.Write("<br/>FormView1_ItemUpdating+FormView1_CurrentMode:
" + FormView1.CurrentMode);
if (FormView1.CurrentMode == FormViewMode.Edit)
{
if (DropDownList1.SelectedValue == "ccc")
{
Response.Write("<br/>Visible: " +
FormView1.FindControl("PlaceHolder1").Visible);
}
}
e.Cancel = true;
}
}
==================================
Hope this helps some. If there is any other questions, please feel free to
let me know.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.