Hi,
Is there ANY WAY to hide a row/field in a DetailsView based on meeting a
condition at the ItemCreated or ModeChanging event -- or any other way?
There appears not to be, but I was hoping for confirmation before
totally giving up.
Thanks,
Kit
actually, after re-reading your post, you want to see how to not show
fields programatically. I did that first and then confused myself to
think you wanted just the other. So, a few control-z's and this has
an example of both getting rid of a field and of getting rid of a
complete attribute. To hide the field, you just set the visible
property of the column in the template.
Good luck and here is the code again with some extra stuff.
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected bool GetShowEmail()
{
// put your logic here to return true or false for visible or
not visible
return false;
}
protected void Page_Load(object sender, EventArgs e)
{
DetailsView1.Fields[2].Visible = false;
}
</script>
<html xmlns="
http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp

etailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataKeyNames="UserName"
DataSourceID="ObjectDataSource1" Height="50px"
Width="125px">
<Fields>
<asp:BoundField DataField="UserName"
HeaderText="UserName" ReadOnly="True" SortExpression="UserName" />
<asp:CheckBoxField DataField="IsApproved"
HeaderText="IsApproved" SortExpression="IsApproved" />
<asp:TemplateField HeaderText="Email"
SortExpression="Email">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("Email") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("Email") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server"
visible='<%# (bool) GetShowEmail() %>' Text='<%# Bind("Email")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp

etailsView>
</div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DeleteMethod="Delete"
InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetMembers"
TypeName="MembershipUtilities.MembershipUserODS"
UpdateMethod="Update">
<DeleteParameters>
<asp

arameter Name="UserName" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp

arameter Name="UserName" Type="String" />
<asp

arameter Name="email" Type="String" />
<asp

arameter Name="isApproved" Type="Boolean" />
<asp

arameter Name="comment" Type="String" />
<asp

arameter Name="lastActivityDate" Type="DateTime"
/>
<asp

arameter Name="lastLoginDate" Type="DateTime" />
<asp

arameter Name="password" Type="String" />
</UpdateParameters>
<SelectParameters>
<asp

arameter Name="sortData" Type="String" />
</SelectParameters>
<InsertParameters>
<asp

arameter Name="userName" Type="String" />
<asp

arameter Name="isApproved" Type="Boolean" />
<asp

arameter Name="comment" Type="String" />
<asp

arameter Name="lastLockoutDate" Type="DateTime"
/>
<asp

arameter Name="creationDate" Type="DateTime" />
<asp

arameter Name="email" Type="String" />
<asp

arameter Name="lastActivityDate" Type="DateTime"
/>
<asp

arameter Name="providerName" Type="String" />
<asp

arameter Name="isLockedOut" Type="Boolean" />
<asp

arameter Name="lastLoginDate" Type="DateTime" />
<asp

arameter Name="isOnline" Type="Boolean" />
<asp

arameter Name="passwordQuestion" Type="String"
/>
<asp

arameter Name="lastPasswordChangedDate"
Type="DateTime" />
<asp

arameter Name="password" Type="String" />
<asp

arameter Name="passwordAnswer" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>
</form>
</body>
</html>
Peter Kellner
http://peterkellner.net