473,287 Members | 3,295 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,287 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 14845
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.