Display multiple records with FormView RRS feed

  • Question

  • User-2080207941 posted


    I have a  a website that I am currently building and would like to know how to display multiple records with FormView. Below is the code that I have so far. It compiles with no errors and if I change the url (http://localhost:64252/ModelBoundWebForm.aspx?id=EX-BBSI01) to match the ProductCodeID  then it only displays that product, but I would like to display them all. how can I achieve this? Also the product ID is completely different for each product.

    ModelBoundWebForm.aspx File

    <div class="container-fluid my-5 product border-top">
            <div class="row">
                    <asp:Formview ID="FVProduct" runat="server" DataKeyNames="ProductCodeId"
                        RenderOuterTable="false" ItemType="ExtremeIron.Models.Product" SelectMethod="FVProduct_GetItem" >
                            <div class="container-fluid my-5 product border-top">
                                <div class="row">
                                    <div class="col-md-6">
                                        <h4 class="text-left mx-3 my-3"><%# Item.ProductName %></h4>
                                        <p class="text-left mx-3"><%# Item.ProductCodeId %></p>
                                        <p class="text-left mx-3">Price: <%# Item.Price %></p>
                                        <p class="text-left mx-3"><%# Item.Description %></p>
                                        <p class="text-left mx-3">Items in Stock: <%# Item.StockQuantity %></p>
                                        <p class="text-left mx-3">Weight: <%# Item.Weight %></p>
                                        <p class="text-left mx-3">In-use Dimensions: <%# Item.InUseDimensions %></p>
                                        <p class="text-left mx-3">Packed Dimensions: <%# Item.PackedDimensions %></p>
                                        <p class="text-left mx-3">Power: <%# Item.Power %></p>
                                        <p class="text-left mx-3">Steam Rate: <%# Item.SteamRate %></p>
                                        <p class="text-left mx-3">Warranty: <%# Item.Warranty %></p>
                                    <div class="col-md-6 my-5 text-center">
                                    <a href='<%# "ModelBoundWebForm.aspx?item=" + Item.ProductCodeId %>' target="_blank">
                                    <img alt='<%# Item.ProductName %>' src='<%# Item.Thumbnail %>'  class="img-thumbnail border-0" />

    ModelBoundWebForm.aspx.cs Code behind C# file

    public Models.Product FVProduct_GetItem()
                string id = Request.QueryString["id"];
                Models.Product product = null;
                    var db = new Models.ExtremeIronDBEntities();
                    product = db.Products.Find(id);
                return product;

    Sunday, May 12, 2019 2:45 AM

All replies

  • User-943250815 posted

    Switch to Repeater or Datalist control, Formview is made to show one record at a time.
    For Reapeater and DataList check this https://docs.microsoft.com/en-us/aspnet/web-forms/overview/data-access/displaying-data-with-the-datalist-and-repeater/displaying-data-with-the-datalist-and-repeater-controls-cs

    Sunday, May 12, 2019 12:56 PM
  • User-1038772411 posted

    Hi, Karlossimo

    You can use following ItemTemplate to make next row in new line.

         rollno: <asp:Label ID="itemLabel" runat="server" Text='<%# Bind("rollno") %>'></asp:Label>
         name: <asp:Label ID="imageLabel" runat="server" Text='<%# Bind("name") %>'> </asp:Label>

    But ,You Can Switch Datalist instead of formviewm, below is complete example code.

    Please Refer Below Link 


    Monday, May 13, 2019 8:26 AM
  • User665608656 posted

    Hi Karlossimo,

    FormView is to display the values of a single record from a data source using user-defined templates. You can refer to this link:


    As the previous two respondents said,I also recommend using the DataList control to show the detailed data by clicking something. 

    I made a demo with Datalist control to show detailed data, you can refer to it. 

    <form id="form1" runat="server">
            <asp:DataList ID="DataList1" runat="server" BackColor="LightGoldenrodYellow"
                BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" OnItemCommand="DataList1_ItemCommand"
                <FooterStyle Font-Bold="True" Font-Italic="False" Font-Size="18pt" />
                <HeaderStyle Font-Bold="True" Font-Size="18pt" />
                <ItemStyle ForeColor="#000066" />
                    <br />
                    <hr />
                    <asp:LinkButton ID="lBtnShowDetails" runat="server" CommandName="select">Details</asp:LinkButton>
                    <%#DataBinder.Eval(Container.DataItem,"FruitName") %>
                    <%#DataBinder.Eval(Container.DataItem,"RowNumber") %>
                    <br />
                    <%#DataBinder.Eval(Container.DataItem,"FruitName") %>
                    <br />
                    <%#DataBinder.Eval(Container.DataItem,"UnitPrice") %>
                    <br />
                    <%#DataBinder.Eval(Container.DataItem,"Quantity") %>
                    <hr />
                    <br />

    code behind:

           protected void Page_Load(object sender, EventArgs e)
            private void DataBindToDataList()
                string connectionString = ConfigurationManager.ConnectionStrings["TestConnectionString1"].ConnectionString;
                SqlConnection connection = new SqlConnection(connectionString);
                SqlDataAdapter sda = new SqlDataAdapter();
                sda.SelectCommand = new SqlCommand("select * from Fruits", connection);
                DataSet ds = new DataSet();
                this.DataList1.DataKeyField = "RowNumber";
                this.DataList1.DataSource = ds.Tables[0];
            protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
                if (e.CommandName == "select")
                    this.DataList1.SelectedIndex = e.Item.ItemIndex;

    The result of my work demo: 


    Best Regards,


    Tuesday, May 14, 2019 5:21 AM