DetailsView formatting

M

Mike P

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?
 
G

Guest

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>
 
M

Mike P

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>
 
G

Guest

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.
 
M

Mike P

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?
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top