473,386 Members | 1,815 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 formatting

The default format for the DetailsView control is for there to be a row
per field. Is it possible set it to show more than one column per row
(see below)?

ID ... Name ...
Address ... Country ...

etc. I have tried to add <tr>'s and <td>'s within the DetailsView to do
this, but it just causes errors.

Anybody know if this can be done, and if so how?

*** Sent via Developersdex http://www.developersdex.com ***
Apr 28 '06 #1
5 11321
Just use Template fields, you could put every column repeated 15 times in one
row if you want. E.g.

<asp:DetailsView ID="dvwCustomerDetails" runat="server"
DataSourceID="sdsCustomerDetails" AutoGenerateRows="False">
<Fields>
<asp:TemplateField HeaderText="Round Number">
<ItemStyle CssClass="details-view-cells" />
<HeaderStyle CssClass="details-view-header" />
<ItemTemplate>
<asp:TextBox ID="txbRoundNumber"
runat="server" Text='<%#Bind("analysis_codes1") %>' MaxLength="10">

</asp:TextBox>
<asp:HiddenField id="hdnPriceList"
runat="server" Value='<%#Bind("price_list") %>'>
</asp:HiddenField>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Driver Number">
<ItemStyle CssClass="details-view-cells" />
<HeaderStyle CssClass="details-view-header" />
<ItemTemplate>
<asp:TextBox ID="txbDriverNumber"
runat="server" Text='<%#Bind("analysis_codes3") %>' MaxLength="10">
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>

"Mike P" wrote:
The default format for the DetailsView control is for there to be a row
per field. Is it possible set it to show more than one column per row
(see below)?

ID ... Name ...
Address ... Country ...

etc. I have tried to add <tr>'s and <td>'s within the DetailsView to do
this, but it just causes errors.

Anybody know if this can be done, and if so how?

*** Sent via Developersdex http://www.developersdex.com ***

Apr 28 '06 #2
Hi,

I am using Template fields, but it seems that they are automatically put
on different rows :

<asp:DetailsView ID="DetailsView1" runat="server"
DataSourceID="SqlDataSource1"
DataKeyNames="OpportunityID"
AutoGenerateRows="False">
<Fields>
<asp:BoundField HeaderText="ID"
DataField="OpportunityID" ReadOnly="True" >
<ItemStyle Height="24px" />
</asp:BoundField>

<asp:TemplateField HeaderText="Product Type"
SortExpression="ProductType">
<ItemTemplate>
<asp:Label ID="lblProductType"
Text='<%# Eval("ProductType") %>' Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList
ID="ddlProductType" runat="server" DataSourceID="SqlDataSource2"

DataTextField="ProductType" DataValueField="ProductTypeID"
SelectedValue='<%#
Bind("ProductTypeID") %>'></asp:DropDownList>
</EditItemTemplate>
<ItemStyle Height="24px" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Opportunity
Type" SortExpression="OpportunityType">
<ItemTemplate>
<asp:Label ID="lblOpportunityType"
Text='<%# Eval("OpportunityType") %>' Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddlOpportunityType"
DataSourceID="SqlDataSource3" Runat="Server"
DataTextField="OpportunityType"
DataValueField="OpportunityTypeID" SelectedValue='<%#
Bind("OpportunityTypeID") %>'/>
</EditItemTemplate>
<ItemStyle Height="24px" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Value (£)"
SortExpression="MonetaryValue">
<ItemTemplate>
<asp:Label ID="lblValue" Text='<%#
Eval("MonetaryValue") %>' Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtValue" Text='<%#
Bind("MonetaryValue") %>' runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtValue"
Display="None" ErrorMessage="Please enter a Value" />
<asp:RangeValidator ID="RangeValidator1"
runat="server"
ControlToValidate="txtValue"
Type="Double" MaximumValue="4000000"
MinimumValue="0" Display="None"
ErrorMessage="Value must be numeric" />
</EditItemTemplate>
<ItemStyle Height="24px" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Description"
SortExpression="Description">
<ItemTemplate>
<asp:Label ID="lblDescription" Text='<%#
Eval("Description") %>' Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtDescription"
Text='<%# Bind("Description") %>' runat="server"
TextMode="MultiLine" Rows="10"
Columns="50"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtDescription"
Display="None" ErrorMessage="Please enter a Description" />
</EditItemTemplate>
<ItemStyle Height="24px" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Probability
(%)" SortExpression="Probability" >
<ItemTemplate>
<asp:Label ID="lblProbability" Text='<%#
Eval("Probability") %>' Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddlProbability"
DataSourceID="SqlDataSource4" Runat="Server"
DataTextField="Probability"
DataValueField="ProbabilityID" SelectedValue='<%# Bind("ProbabilityID")
%>'/>
</EditItemTemplate>
<ItemStyle Height="24px" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Location"
SortExpression="Location">
<ItemTemplate>
<asp:Label ID="lblLocation" Text='<%#
Eval("Location") %>' Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtLocation" Text='<%#
Bind("Location") %>' runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtLocation"
Display="None" ErrorMessage="Please enter a Location" />
</EditItemTemplate>
<ItemStyle Height="24px" />
</asp:TemplateField>

<asp:BoundField HeaderText="Company Name"
DataField="CompanyName" ReadOnly="True" >
<ItemStyle Height="24px" />
</asp:BoundField>

<asp:BoundField HeaderText="Date Created"
DataField="DateCreated" ReadOnly="True" >
<ItemStyle Height="24px" />
</asp:BoundField>

<asp:TemplateField HeaderText="Status"
SortExpression="OpportunityStatus">
<ItemTemplate>
<asp:Label ID="lblOpportunityStatus"
Text='<%# Eval("OpportunityStatus") %>' Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList
id="ddlOpportunityStatus" DataSourceID="SqlDataSource5" Runat="Server"
DataTextField="OpportunityStatus"
DataValueField="OpportunityStatusID" SelectedValue='<%#
Bind("OpportunityStatusID") %>'/>
</EditItemTemplate>
<ItemStyle Height="24px" />
</asp:TemplateField>

<asp:BoundField HeaderText="Date Won/Lost"
DataField="DateWonOrLost" NullDisplayText="N/A" ReadOnly="True" >
<ItemStyle Height="24px" />
</asp:BoundField>

<asp:CommandField ShowEditButton="True"
ButtonType="Image" EditImageUrl="~/Images/btnEdit.jpg"
CancelImageUrl="~/Images/btnCancel.jpg"
UpdateImageUrl="~/Images/btnUpdate.jpg" >
<ItemStyle Height="10px" />
</asp:CommandField>

</Fields>
</asp:DetailsView>
*** Sent via Developersdex http://www.developersdex.com ***
Apr 28 '06 #3
Yes but there is nothing stopping you putting whatever you want within
however many or few template fierlds as you want. The markup below looks
like what gets generated when you turn BoundFields into TemplateFields. Now
edit it to be how you want it. If you want two items in one template field
simply cut and paste the contents of each ItemTemplate, UpdateTemplate and
InsertTemplate from one templatefield to another and delete the extra
templatefield. The dta is bound to the controls within the templatefield,
the templatefield it's self is just a container and does not have any data
bound to it.

"Mike P" wrote:
Hi,

I am using Template fields, but it seems that they are automatically put
on different rows :

<asp:DetailsView ID="DetailsView1" runat="server"
DataSourceID="SqlDataSource1"
DataKeyNames="OpportunityID"
AutoGenerateRows="False">
<Fields>
<asp:BoundField HeaderText="ID"
DataField="OpportunityID" ReadOnly="True" >
<ItemStyle Height="24px" />
</asp:BoundField>

<asp:TemplateField HeaderText="Product Type"
SortExpression="ProductType">
<ItemTemplate>
<asp:Label ID="lblProductType"
Text='<%# Eval("ProductType") %>' Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList
ID="ddlProductType" runat="server" DataSourceID="SqlDataSource2"

DataTextField="ProductType" DataValueField="ProductTypeID"
SelectedValue='<%#
Bind("ProductTypeID") %>'></asp:DropDownList>
</EditItemTemplate>
<ItemStyle Height="24px" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Opportunity
Type" SortExpression="OpportunityType">
<ItemTemplate>
<asp:Label ID="lblOpportunityType"
Text='<%# Eval("OpportunityType") %>' Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddlOpportunityType"
DataSourceID="SqlDataSource3" Runat="Server"
DataTextField="OpportunityType"
DataValueField="OpportunityTypeID" SelectedValue='<%#
Bind("OpportunityTypeID") %>'/>
</EditItemTemplate>
<ItemStyle Height="24px" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Value (#)"
SortExpression="MonetaryValue">
<ItemTemplate>
<asp:Label ID="lblValue" Text='<%#
Eval("MonetaryValue") %>' Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtValue" Text='<%#
Bind("MonetaryValue") %>' runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtValue"
Display="None" ErrorMessage="Please enter a Value" />
<asp:RangeValidator ID="RangeValidator1"
runat="server"
ControlToValidate="txtValue"
Type="Double" MaximumValue="4000000"
MinimumValue="0" Display="None"
ErrorMessage="Value must be numeric" />
</EditItemTemplate>
<ItemStyle Height="24px" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Description"
SortExpression="Description">
<ItemTemplate>
<asp:Label ID="lblDescription" Text='<%#
Eval("Description") %>' Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtDescription"
Text='<%# Bind("Description") %>' runat="server"
TextMode="MultiLine" Rows="10"
Columns="50"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtDescription"
Display="None" ErrorMessage="Please enter a Description" />
</EditItemTemplate>
<ItemStyle Height="24px" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Probability
(%)" SortExpression="Probability" >
<ItemTemplate>
<asp:Label ID="lblProbability" Text='<%#
Eval("Probability") %>' Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddlProbability"
DataSourceID="SqlDataSource4" Runat="Server"
DataTextField="Probability"
DataValueField="ProbabilityID" SelectedValue='<%# Bind("ProbabilityID")
%>'/>
</EditItemTemplate>
<ItemStyle Height="24px" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Location"
SortExpression="Location">
<ItemTemplate>
<asp:Label ID="lblLocation" Text='<%#
Eval("Location") %>' Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtLocation" Text='<%#
Bind("Location") %>' runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtLocation"
Display="None" ErrorMessage="Please enter a Location" />
</EditItemTemplate>
<ItemStyle Height="24px" />
</asp:TemplateField>

<asp:BoundField HeaderText="Company Name"
DataField="CompanyName" ReadOnly="True" >
<ItemStyle Height="24px" />
</asp:BoundField>

<asp:BoundField HeaderText="Date Created"
DataField="DateCreated" ReadOnly="True" >
<ItemStyle Height="24px" />
</asp:BoundField>

<asp:TemplateField HeaderText="Status"
SortExpression="OpportunityStatus">
<ItemTemplate>
<asp:Label ID="lblOpportunityStatus"
Text='<%# Eval("OpportunityStatus") %>' Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList
id="ddlOpportunityStatus" DataSourceID="SqlDataSource5" Runat="Server"
DataTextField="OpportunityStatus"
DataValueField="OpportunityStatusID" SelectedValue='<%#
Bind("OpportunityStatusID") %>'/>
</EditItemTemplate>
<ItemStyle Height="24px" />
</asp:TemplateField>

<asp:BoundField HeaderText="Date Won/Lost"
DataField="DateWonOrLost" NullDisplayText="N/A" ReadOnly="True" >
<ItemStyle Height="24px" />
</asp:BoundField>

<asp:CommandField ShowEditButton="True"
ButtonType="Image" EditImageUrl="~/Images/btnEdit.jpg"
CancelImageUrl="~/Images/btnCancel.jpg"
UpdateImageUrl="~/Images/btnUpdate.jpg" >
<ItemStyle Height="10px" />
</asp:CommandField>

</Fields>
</asp:DetailsView>
*** Sent via Developersdex http://www.developersdex.com ***

Apr 28 '06 #4
How does this work if you have mixture of Bound Fields and Template
Fields, since you are not allowed to put Bound Fields within Template
Fields?

*** Sent via Developersdex http://www.developersdex.com ***
Apr 28 '06 #5
Boundfields are of faily limited use, i rarely use them at all. There is
never a circumstance where it would be usefull to put a boundfield inside a
templatefield. If you want the value from a bound field to be inside a
template field. simply delete the boundfield put another control in
itemtemplate, edittemplate and/or inserttemplate sections of the the
templatefield as apropraite. Then bind that control to the relevent column
within your table using the following syntax.

<asp:textbox id="MyTextBox" runat="server" text='<%#
Bind("FieldName")%>'></asp:textbox>

Remember, BoundFields are just a quick way of displaying data from a
database, they are almost useless for updateing and inserting data and are of
only limited use for displaying data, as you have discovered.

"Mike P" wrote:
How does this work if you have mixture of Bound Fields and Template
Fields, since you are not allowed to put Bound Fields within Template
Fields?

*** Sent via Developersdex http://www.developersdex.com ***

Apr 28 '06 #6

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

Similar topics

1
by: Shawn Wildermuth | last post by:
I have a *single* SqlDataSource that loads up a single result set that I show in a GridView. In the GridView, i've added a "Select" button and handling the SelectedItem event. I also have a...
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...
1
by: sck10 | last post by:
Hello, I am trying to change a value when a user goes into edit mode on a DetailsView control. I am trying to use the following, but can not figure out how to get to the bound field...
4
by: Frits van Soldt | last post by:
Hello, I hope somebody can help me with this! I have 2 listboxes in the edititemtemplate of a detailsview. In the databound event of the detailsview I would like to fill the listboxes...
1
by: Marko Loukkaanhuhta | last post by:
Hi, this might be newbies question, but hey I'm newbie.. I'm trying to make a web site which you can use to read and update data from sql server. Data on the sql server is text. Data fields in...
0
by: mike | last post by:
Hi, When I programatically Bind a DataSource to DetailsView it does not fire "ModeChanged" event. This is first time i am trying to use ASP.NET DetailsView control. I have played with some of the...
2
by: Curious Trigger | last post by:
Hello, if have an asp.net web page with a detailsview. This detailsview uses a sqldatasource connecting to a sql server 2005 database with a select statement simliar to this one: SELECT...
1
by: needhelp1 | last post by:
I have gridview with a detailsview below. When I click on 'New' in brings up the DetailsView for inserting. When I click on 'Edit' in does not brink up the DetailsView. What am I doing wrong? I...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.