Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DetailsView formatting

Reply
Thread Tools

DetailsView formatting

 
 
Mike P
Guest
Posts: n/a
 
      04-28-2006
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 ***
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Y2xpY2tvbg==?=
Guest
Posts: n/a
 
      04-28-2006
Just use Template fields, you could put every column repeated 15 times in one
row if you want. E.g.

<aspetailsView 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>
</aspetailsView>



"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 ***
>

 
Reply With Quote
 
 
 
 
Mike P
Guest
Posts: n/a
 
      04-28-2006
Hi,

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

<aspetailsView 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>
<aspropDownList
ID="ddlProductType" runat="server" DataSourceID="SqlDataSource2"

DataTextField="ProductType" DataValueField="ProductTypeID"
SelectedValue='<%#
Bind("ProductTypeID") %>'></aspropDownList>
</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>
<aspropDownList 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>
<aspropDownList 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>
<aspropDownList
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>
</aspetailsView>


*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
=?Utf-8?B?Y2xpY2tvbg==?=
Guest
Posts: n/a
 
      04-28-2006
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 :
>
> <aspetailsView 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>
> <aspropDownList
> ID="ddlProductType" runat="server" DataSourceID="SqlDataSource2"
>
> DataTextField="ProductType" DataValueField="ProductTypeID"
> SelectedValue='<%#
> Bind("ProductTypeID") %>'></aspropDownList>
> </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>
> <aspropDownList 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>
> <aspropDownList 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>
> <aspropDownList
> 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>
> </aspetailsView>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
>

 
Reply With Quote
 
Mike P
Guest
Posts: n/a
 
      04-28-2006
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 ***
 
Reply With Quote
 
=?Utf-8?B?Y2xpY2tvbg==?=
Guest
Posts: n/a
 
      04-28-2006
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 ***
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting phone number of a DetailsView control womblesjc@royell.org ASP .Net 1 03-22-2006 11:38 PM
DetailsView - Changing to Insert Mode (Not By Using the Insert Button In the DetailsView Control) Feege ASP .Net Web Controls 0 12-20-2005 12:28 AM
Binding a textbox to a detailsview in asp.net 2.0 =?Utf-8?B?Q2VyaV9EYXZpZXM=?= ASP .Net 0 03-22-2005 06:11 PM
How to add the DropDownList and TextBox Control in DetailsView Murugan V via DotNetMonster.com ASP .Net 0 01-08-2005 09:27 AM
Need formatting options menu for formatting hard drive Mark T. Computer Support 3 11-24-2003 11:50 PM



Advertisments