473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 14850
On Wed, 17 May 2006 18:40:12 -0700, K B <ka**********@comcast.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.dtd">

<script runat="server">

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:DetailsView 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"
Text='<%# Bind("Email") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>

</div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DeleteMethod="Delete"
InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetMembers"
TypeName="MembershipUtilities.MembershipUserODS"
UpdateMethod="Update">
<DeleteParameters>
<asp:Parameter Name="UserName" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="isApproved" Type="Boolean" />
<asp:Parameter Name="comment" Type="String" />
<asp:Parameter Name="lastActivityDate" Type="DateTime"
/>
<asp:Parameter Name="lastLoginDate" Type="DateTime" />
<asp:Parameter Name="password" Type="String" />
</UpdateParameters>
<SelectParameters>
<asp:Parameter Name="sortData" Type="String" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="userName" Type="String" />
<asp:Parameter Name="isApproved" Type="Boolean" />
<asp:Parameter Name="comment" Type="String" />
<asp:Parameter Name="lastLockoutDate" Type="DateTime"
/>
<asp:Parameter Name="creationDate" Type="DateTime" />
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="lastActivityDate" Type="DateTime"
/>
<asp:Parameter Name="providerName" Type="String" />
<asp:Parameter Name="isLockedOut" Type="Boolean" />
<asp:Parameter Name="lastLoginDate" Type="DateTime" />
<asp:Parameter Name="isOnline" Type="Boolean" />
<asp:Parameter Name="passwordQuestion" Type="String"
/>
<asp:Parameter Name="lastPasswordChangedDate"
Type="DateTime" />
<asp:Parameter Name="password" Type="String" />
<asp:Parameter Name="passwordAnswer" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>
</form>
</body>
</html>
Peter Kellner
http://peterkellner.net
May 18 '06 #2
On Wed, 17 May 2006 18:40:12 -0700, K B <ka**********@comcast.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.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:DetailsView 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:DetailsView>

</div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DeleteMethod="Delete"
InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetMembers"
TypeName="MembershipUtilities.MembershipUserODS"
UpdateMethod="Update">
<DeleteParameters>
<asp:Parameter Name="UserName" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="isApproved" Type="Boolean" />
<asp:Parameter Name="comment" Type="String" />
<asp:Parameter Name="lastActivityDate" Type="DateTime"
/>
<asp:Parameter Name="lastLoginDate" Type="DateTime" />
<asp:Parameter Name="password" Type="String" />
</UpdateParameters>
<SelectParameters>
<asp:Parameter Name="sortData" Type="String" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="userName" Type="String" />
<asp:Parameter Name="isApproved" Type="Boolean" />
<asp:Parameter Name="comment" Type="String" />
<asp:Parameter Name="lastLockoutDate" Type="DateTime"
/>
<asp:Parameter Name="creationDate" Type="DateTime" />
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="lastActivityDate" Type="DateTime"
/>
<asp:Parameter Name="providerName" Type="String" />
<asp:Parameter Name="isLockedOut" Type="Boolean" />
<asp:Parameter Name="lastLoginDate" Type="DateTime" />
<asp:Parameter Name="isOnline" Type="Boolean" />
<asp:Parameter Name="passwordQuestion" Type="String"
/>
<asp:Parameter Name="lastPasswordChangedDate"
Type="DateTime" />
<asp:Parameter Name="password" Type="String" />
<asp:Parameter Name="passwordAnswer" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>
</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
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...
3
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...
0
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...
3
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...
3
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...
3
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...
2
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...
1
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...
5
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:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...

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.