473,748 Members | 6,037 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DetailsView - Hide row/field conditionally?

K B
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 ***
May 18 '06 #1
2 14881
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 ***

You can access the "fields" collection and set them invisible. Ignore
the fact that I converted the email column to a template. I was just
experimenting.

Here is an example that turns off the email column in the page_load
event.

<%@ 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 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"
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
May 18 '06 #2
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
May 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
8703
by: Jim Hammond | last post by:
I am passing the whole object instead or parameters in my select and update methods. I can get the updated object if I set UpdateMethod, let ASP.NET autogenerate an update button, and then press update after making changes, but I don't want that update button. How can I get the updated object when the user presses one of my other action buttons?
3
4071
by: chrisn | last post by:
Hi, (Using ASP.Net 2.0) I have a wizard control inside a detailsview control. When I attempt to call the InsertItem method on the DetailsView I get an error "ObjectDataSource 'ObjectDataSource1' has no values to insert. Check that the 'values' dictionary contains values." I have found I can suppress the error by placing a hidden field inside
0
1874
by: jeffmagill | last post by:
Hi Everybody, I'm really hoping that someone can help me out because I have spent too much time on this project already! Basically, I have a DetailsView that handles all the Edits for a GridView - each row has an edit button and clicking on this should trigger that record to be loaded into the DetailsView for editing. The problem is that the record never gets loaded into the DetailsView. Instead, the DetailsView always and only...
3
7730
by: | last post by:
I'm using the DataList and GridView controls, and I am trying to wrap my head around the problem of conditionally showing or hiding cells/cell content based on the presence or absence of DB data. I am finding this sort of problem by far the most annoying part about working with ASP.NET controls. What I want is to know how to do three things: - conditionally show or hide an ImageField +column+ based on whether or not an the...
3
1493
by: NEWS | last post by:
I am using a DetailsView control in ASP.Net / Visual Studio 2005 in a website project. The DetailsView contains a number of fields. the second field is a customerID field which i need to calculate and display automatically depending on what the user enters into the first field. I need a GotFocus or LoseFocus event so i can run some code when the user leave;s the first input field.
3
5189
by: rn5a | last post by:
How do I change the BorderColor of the rows under the 2nd column in a DetailsView? I could change the BorderColor of the 1st column using the FieldHeaderStyle-BorderColor property but using RowStyle-BorderColor, the BorderColor of the 2nd column just refuses to change. I even tried using AlternatingRowStyle-BorderColor but that doesn't make any difference. What is surprising is the other properties of RowStyle & AlternatingRowStyle...
2
9729
by: Bazza Formez | last post by:
I have a bound field in a DetailsView control that displays free form description type data from my SQL database table (typical data is a couple of paragraphs of written product description being held in a single database field of type ntext). This description data typically has various simple control characters in it - ie. new line, carriage returns etc) to make the paragraph more readable. My problem is that these control characters...
1
4955
by: nithingujjar | last post by:
Hi, I need to to hide a field"addr_state1" based on a value in the drop down list field called "addr_country".i.e.,if addr_country.value=="in" then hide addr_state1 else , and if the value in the selection changes to something else then show the field addr_state1. Also the addr_state1 should be hidden when the page loads with value "IN", and if the page loads some other value than show the addr_state1 field. Code used for this is :(I have to...
5
3462
by: =?Utf-8?B?bXBhaW5l?= | last post by:
Hello, I am completely lost as to why I can't update a DropDownList inside a DetailsView after I perform an insert into an object datasource. I tried to simply it down to the core demostration: default.aspx:
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9544
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4606
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.