Solved

FormView control only displays one row of data

Posted on 2010-08-17
2
458 Views
Last Modified: 2012-05-10
My FormView control only displays the first row returned by my sql query. What am i doing wrong?

<asp:SqlDataSource ID="sds1" runat="server" ConnectionString ="<%$ ConnectionStrings:conn %>"
        SelectCommand="SELECT title_id,title, type, price, notes, pubdate FROM titles ORDER BY title"
        UpdateCommand="UPDATE titles SET title = @title, type = @type, price=@price, notes=@notes, pubdate=@pubdate WHERE title_id = @title_id">
            <UpdateParameters>
        <asp:Parameter Type="String" Name="title"></asp:Parameter>
                  <asp:Parameter Type="String" Name="type"></asp:Parameter>
                <asp:Parameter Type="Decimal" Name="price"></asp:Parameter>
                  <asp:Parameter Type="String" Name="notes"></asp:Parameter>
                  <asp:Parameter Type="DateTime" Name="pubdate"></asp:Parameter>
                <asp:Parameter Type="String" Name="title_id"></asp:Parameter>
            </UpdateParameters>
</asp:SqlDataSource>
            <asp:SqlDataSource ID="sds2" runat="server" ConnectionString ="<%$ ConnectionStrings:conn %>" SelectCommand="SELECT DISTINCT type FROM titles"></asp:SqlDataSource>
            <asp:FormView ID="FormView1" runat="server" DataSourceID="sds1" DataKeyNames="title_id" CellPadding="4" DataMember="DefaultView" ForeColor="#333333">
            <ItemTemplate>
            <table>
            <tr>
            <td>
             <asp:Label ID="lblID" runat="server"
                          Text='<%#Eval("title_id") %>' Visible="false">
    </asp:Label>
    </td>
  <td>
    <asp:Label ID="lblTitle" runat="server"
               Text='<%#Eval("Title") %>'>
    </asp:Label>
   </td>
   <td>
                <asp:DropDownList ID="ddlType" DataSourceID="sds2" DataTextField="type" DataValueField="type"  SelectedValue='<%# Bind("type") %>' runat="server" Width="130px"></asp:DropDownList>
                </td>
                <td>
    <asp:Label ID="lblPrice" runat="server"
               Text='<%# Eval("price", "{0:c}")  %>'>
    </asp:Label>
    </td>
                <td>
    <asp:Label ID="lblNotes" runat="server"
               Text='<%#Eval("notes") %>'>
    </asp:Label>
    </td>
            </tr>
            </table>
            </ItemTemplate>
            <EditItemTemplate>
            <table>
            <tr>
              <td>
    <asp:TextBox ID="txtTitle" runat="server"
                 Text='<%#Bind("Title") %>'>
    </asp:TextBox>
   </td>
   <td>
                <asp:DropDownList ID="ddlType" DataSourceID="sds2" DataTextField="type" DataValueField="type"  SelectedValue='<%# Bind("type") %>' runat="server" Width="130px"></asp:DropDownList>
                </td>
   <td>
    <asp:TextBox ID="txtPrice" runat="server"
                 Text='<%#Bind("price") %>'>
    </asp:TextBox>
     </td>
   <td>
    <asp:TextBox ID="txtNotes" runat="server"
                 Text='<%#Bind("notes") %>' TextMode="MultiLine" Rows="3" Width="300">
    </asp:TextBox>
    </td>
   <td>
    <asp:TextBox ID="txtPubDate" runat="server"
                 Text='<%#Bind("pubdate") %>'>
    </asp:TextBox>
    </td>
            </tr>
            </table>
            </EditItemTemplate>
                <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            </asp:FormView>
0
Comment
Question by:YZlat
2 Comments
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 500 total points
ID: 33458890
You are doing nothing wrong....as the MSDN states (emphasis added):

"In the FormView control, a page of data is a SINGLE BOUND RECORD. If you set the AllowPaging property of the FormView control to true, the FormView control automatically adds user interface (UI) controls for paging. You can customize the UI for paging by adding a PagerTemplate template. For details, see Paging in a FormView Web Server Control."
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 33459746
As mentioned above FV will display one item at a time.
And if you want to display multiple rows you will have to use another controls like Repeater/DataList or ListView.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mail.To.Add 5 25
jquery datatables, asp.net MVC 9 40
Need to learn more about SecurityProtocolType.Tls12 3 29
ASP.NET MVC -Add authentication 2 21
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question