Hello Andrew,
From your description, you're putting a placeholder control in FromView's
EditTemplate, and you'll programmaticall y 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 programmaticall y 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>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownLi st ID="DropDownLis t1" runat="server">
<asp:ListItem>a aa</asp:ListItem>
<asp:ListItem>b bb</asp:ListItem>
<asp:ListItem>c cc</asp:ListItem>
<asp:ListItem>d dd</asp:ListItem>
</asp:DropDownLis t><br />
<asp:FormView ID="FormView1" runat="server"
DataKeyNames="A ddressTypeID" DataSourceID="S qlDataSource1"
OnItemCreated=" FormView1_ItemC reated"
OnItemUpdating= "FormView1_Item Updating" OnLoad="FormVie w1_Load"
OnModeChanged=" FormView1_ModeC hanged">
<EditItemTempla te>
AddressTypeID:
<asp:Label ID="AddressType IDLabel1" runat="server"
Text='<%# Eval("AddressTy peID") %>'></asp:Label><br />
Name:
<asp:TextBox ID="NameTextBox " runat="server" Text='<%#
Bind("Name") %>'></asp:TextBox><br />
<hr />
<asp:PlaceHolde r ID="PlaceHolder 1" runat="server">
<table>
<tr>
<td>
<asp:Label ID="lblResponse Text"
runat="server"> Response Text: </asp:Label></td>
<td>
<asp:TextBox ID="tbResponseT ext"
runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</td>
</tr>
</table>
</asp:PlaceHolder >
<br />
<hr />
<br />
<asp:LinkButt on ID="UpdateButto n" runat="server"
CausesValidatio n="True" CommandName="Up date"
Text="Update"></asp:LinkButton>
<asp:LinkButt on ID="UpdateCance lButton" runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
Text="Cancel"></asp:LinkButton>
</EditItemTemplat e>
<InsertItemTemp late>
Name:
<asp:TextBox ID="NameTextBox " runat="server" Text='<%#
Bind("Name") %>'>
</asp:TextBox><br />
<asp:LinkButt on ID="InsertButto n" runat="server"
CausesValidatio n="True" CommandName="In sert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButt on ID="InsertCance lButton" runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTempl ate>
<ItemTemplate >
AddressTypeID:
<asp:Label ID="AddressType IDLabel" runat="server" Text='<%#
Eval("AddressTy peID") %>'></asp:Label><br />
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%#
Bind("Name") %>'></asp:Label><br />
<asp:LinkButt on ID="EditButton " runat="server"
CausesValidatio n="False" CommandName="Ed it"
Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:FormView>
</div>
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:AdventureWor ksConnectionStr ing %>"
SelectCommand=" SELECT AddressTypeID, Name FROM
Person.AddressT ype" UpdateCommand=" UPDATE Person.AddressT ype SET">
</asp:SqlDataSour ce>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>
=========code behind========= ====
public partial class FormViewPage : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
}
protected void FormView1_ItemC reated(object sender, EventArgs e)
{
}
protected void FormView1_ModeC hanged(object sender, EventArgs e)
{
}
protected void FormView1_Load( object sender, EventArgs e)
{
Response.Write( "<br/>FormView1_Load +FormView1_Curr entMode: " +
FormView1.Curre ntMode);
if (FormView1.Curr entMode == FormViewMode.Ed it)
{
if (DropDownList1. SelectedValue == "ccc")
{
FormView1.FindC ontrol("PlaceHo lder1").Visible = true;
}
else
{
FormView1.FindC ontrol("PlaceHo lder1").Visible = false;
}
}
}
protected void FormView1_ItemU pdating(object sender,
FormViewUpdateE ventArgs e)
{
Response.Write( "<br/>FormView1_Item Updating+FormVi ew1_CurrentMode :
" + FormView1.Curre ntMode);
if (FormView1.Curr entMode == FormViewMode.Ed it)
{
if (DropDownList1. SelectedValue == "ccc")
{
Response.Write( "<br/>Visible: " +
FormView1.FindC ontrol("PlaceHo lder1").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/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.