locked
Customize Details View fields placemement RRS feed

  • Question

  • User-535947265 posted

    hi friends, excuseme for this, i think is very simple but im a newbbie.

    In my first asp.net c# site i have a detail page and placed a detailsview control, that is great but, is anyway to separe fields?? they are in a table and i want to place some fields at top of page, others fields must be inside divs (bootstrap formatted) etc. is it possible to do this? is it something i missed like another kind of control?

    on this page just want to show detail, this is not for editing so there is not problem to place fields in any place of my page

    thanks in advance for your help

    Wednesday, June 1, 2016 10:53 PM

All replies

  • User1559292362 posted

    Hi juangatito,

    In my first asp.net c# site i have a detail page and placed a detailsview control, that is great but, is anyway to separe fields?? they are in a table and i want to place some fields at top of page, others fields must be inside divs (bootstrap formatted) etc. is it possible to do this?

    you could use TemplateField to ahieve it, like this:

    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
        DataKeyNames="ProductID" DataSourceID="ObjectDataSource1" AllowPaging="True"
        EnableViewState="False">
        <Fields>
            <asp:BoundField DataField="ProductName"
              HeaderText="Product" SortExpression="ProductName" />
            <asp:BoundField DataField="CategoryName" HeaderText="Category"
              ReadOnly="True" SortExpression="CategoryName" />
            <asp:BoundField DataField="SupplierName"
              HeaderText="Supplier" ReadOnly="True"
              SortExpression="SupplierName" />
            <asp:BoundField DataField="QuantityPerUnit"
              HeaderText="Qty/Unit" SortExpression="QuantityPerUnit" />
            <asp:TemplateField HeaderText="Price and Inventory">
                <ItemTemplate>
    <table><tr><td>
                    <asp:Label ID="Label1" runat="server"
                      Text='<%# Eval("UnitPrice", "{0:C}") %>'></asp:Label>
                    <br />
                    <strong>
                    (In Stock / On Order: </strong>
                    <asp:Label ID="Label2" runat="server"
                      Text='<%# Eval("UnitsInStock") %>'></asp:Label>
                    <strong>/</strong>
                    <asp:Label ID="Label3" runat="server"
                      Text='<%# Eval("UnitsOnOrder") %>'>
                    </asp:Label><strong>)</strong>
    </td></tr></table>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CheckBoxField DataField="Discontinued"
               HeaderText="Discontinued" SortExpression="Discontinued" />
        </Fields>
    </asp:DetailsView>

    For more information, please refer to:

    http://www.asp.net/web-forms/overview/data-access/custom-formatting/using-templatefields-in-the-detailsview-control-cs

    is it something i missed like another kind of control?

    Based on requirement, I would suggest that you could use FormView to achieve it, which you could More flexible to customize your template.

    <asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1"
        AllowPaging="True" EnableViewState="False">
        <ItemTemplate>
            <hr />
            <h3><%# Eval("ProductName") %></h3>
            <table border="0">
                <tr>
                    <td class="ProductPropertyLabel">Category:</td>
                    <td class="ProductPropertyValue">
                      <%# Eval("CategoryName") %></td>
                    <td class="ProductPropertyLabel">Supplier:</td>
                    <td class="ProductPropertyValue">
                      <%# Eval("SupplierName")%></td>
                </tr>
                <tr>
                    <td class="ProductPropertyLabel">Price:</td>
                    <td class="ProductPropertyValue"><%# Eval("UnitPrice",
                      "{0:C}") %></td>
                    <td class="ProductPropertyLabel">Units In Stock:</td>
                    <td class="ProductPropertyValue">
                      <%# Eval("UnitsInStock")%></td>
                </tr>
                <tr>
                    <td class="ProductPropertyLabel">Units On Order:</td>
                    <td class="ProductPropertyValue">
                      <%# Eval("UnitsOnOrder") %></td>
                    <td class="ProductPropertyLabel">Reorder Level:</td>
                    <td class="ProductPropertyValue">
                      <%# Eval("ReorderLevel")%></td>
                </tr>
                <tr>
                    <td class="ProductPropertyLabel">Qty/Unit</td>
                    <td class="ProductPropertyValue">
                      <%# Eval("QuantityPerUnit") %></td>
                    <td class="ProductPropertyLabel">Discontinued:</td>
                    <td class="ProductPropertyValue">
                        <asp:CheckBox runat="server" Enabled="false"
                          Checked='<%# Eval("Discontinued") %>' />
                    </td>
                </tr>
            </table>
            <hr />
        </ItemTemplate>
    </asp:FormView>

    For more information, please refer to:

    http://www.asp.net/web-forms/overview/data-access/custom-formatting/using-the-formview-s-templates-cs

    Best regards,

    Cole Wu

    Thursday, June 2, 2016 7:32 AM
  • User-535947265 posted

    thanks for this, ill try and will back to post my comments

    have a nice day

    Friday, June 3, 2016 12:15 AM
  • User1559292362 posted

    Hi juangatito,

    thanks for this, ill try and will back to post my comments

    Do you try the code? Could it meets your requirement? If you have any question, please feel free let me know.

    Best regards,

    Cole Wu

    Tuesday, June 14, 2016 1:20 AM