DetailsView formatting

Discussion in 'ASP .Net' started by Mike P, Apr 28, 2006.

  1. Mike P

    Mike P Guest

    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 ***
    Mike P, Apr 28, 2006
    #1
    1. Advertising

  2. 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 ***
    >
    =?Utf-8?B?Y2xpY2tvbg==?=, Apr 28, 2006
    #2
    1. Advertising

  3. Mike P

    Mike P Guest

    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 ***
    Mike P, Apr 28, 2006
    #3
  4. 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 ***
    >
    =?Utf-8?B?Y2xpY2tvbg==?=, Apr 28, 2006
    #4
  5. Mike P

    Mike P Guest

    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 ***
    Mike P, Apr 28, 2006
    #5
  6. 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 ***
    >
    =?Utf-8?B?Y2xpY2tvbg==?=, Apr 28, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Murugan V via DotNetMonster.com

    How to add the DropDownList and TextBox Control in DetailsView

    Murugan V via DotNetMonster.com, Jan 8, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    659
    Murugan V via DotNetMonster.com
    Jan 8, 2005
  2. =?Utf-8?B?Q2VyaV9EYXZpZXM=?=

    Binding a textbox to a detailsview in asp.net 2.0

    =?Utf-8?B?Q2VyaV9EYXZpZXM=?=, Mar 22, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    986
    =?Utf-8?B?Q2VyaV9EYXZpZXM=?=
    Mar 22, 2005
  3. podong28
    Replies:
    1
    Views:
    1,832
    Brock Allen
    Apr 20, 2005
  4. Replies:
    1
    Views:
    2,982
    =?Utf-8?B?Y2xpY2tvbg==?=
    Mar 22, 2006
  5. Feege
    Replies:
    0
    Views:
    446
    Feege
    Dec 20, 2005
Loading...

Share This Page