On Wed, 17 May 2006 18:40:12 -0700, K B <ka**********@c omcast.net>
wrote:
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
*** Sent via Developersdex http://www.developersdex.com ***
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.dt d">
<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(objec t sender, EventArgs e)
{
DetailsView1.Fi elds[2].Visible = false;
}
</script>
<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:DetailsVie w ID="DetailsView 1" runat="server"
AutoGenerateRow s="False" DataKeyNames="U serName"
DataSourceID="O bjectDataSource 1" Height="50px"
Width="125px">
<Fields>
<asp:BoundFie ld DataField="User Name"
HeaderText="Use rName" ReadOnly="True" SortExpression= "UserName" />
<asp:CheckBoxFi eld DataField="IsAp proved"
HeaderText="IsA pproved" SortExpression= "IsApproved " />
<asp:TemplateFi eld HeaderText="Ema il"
SortExpression= "Email">
<EditItemTempla te>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("Email") %>'></asp:TextBox>
</EditItemTemplat e>
<InsertItemTemp late>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("Email") %>'></asp:TextBox>
</InsertItemTempl ate>
<ItemTemplate >
<asp:Label ID="Label1" runat="server"
visible='<%# (bool) GetShowEmail() %>' Text='<%# Bind("Email")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
</Fields>
</asp:DetailsView >
</div>
<asp:ObjectData Source ID="ObjectDataS ource1" runat="server"
DeleteMethod="D elete"
InsertMethod="I nsert"
OldValuesParame terFormatString ="original_{ 0}"
SelectMethod="G etMembers"
TypeName="Membe rshipUtilities. MembershipUserO DS"
UpdateMethod="U pdate">
<DeleteParamete rs>
<asp:Paramete r Name="UserName" Type="String" />
</DeleteParameter s>
<UpdateParamete rs>
<asp:Paramete r Name="UserName" Type="String" />
<asp:Paramete r Name="email" Type="String" />
<asp:Paramete r Name="isApprove d" Type="Boolean" />
<asp:Paramete r Name="comment" Type="String" />
<asp:Paramete r Name="lastActiv ityDate" Type="DateTime"
/>
<asp:Paramete r Name="lastLogin Date" Type="DateTime" />
<asp:Paramete r Name="password" Type="String" />
</UpdateParameter s>
<SelectParamete rs>
<asp:Paramete r Name="sortData" Type="String" />
</SelectParameter s>
<InsertParamete rs>
<asp:Paramete r Name="userName" Type="String" />
<asp:Paramete r Name="isApprove d" Type="Boolean" />
<asp:Paramete r Name="comment" Type="String" />
<asp:Paramete r Name="lastLocko utDate" Type="DateTime"
/>
<asp:Paramete r Name="creationD ate" Type="DateTime" />
<asp:Paramete r Name="email" Type="String" />
<asp:Paramete r Name="lastActiv ityDate" Type="DateTime"
/>
<asp:Paramete r Name="providerN ame" Type="String" />
<asp:Paramete r Name="isLockedO ut" Type="Boolean" />
<asp:Paramete r Name="lastLogin Date" Type="DateTime" />
<asp:Paramete r Name="isOnline" Type="Boolean" />
<asp:Paramete r Name="passwordQ uestion" Type="String"
/>
<asp:Paramete r Name="lastPassw ordChangedDate"
Type="DateTime" />
<asp:Paramete r Name="password" Type="String" />
<asp:Paramete r Name="passwordA nswer" Type="String" />
</InsertParameter s>
</asp:ObjectDataS ource>
</form>
</body>
</html>
Peter Kellner
http://peterkellner.net