Solved

FormView control only displays one row of data

Posted on 2010-08-17
2
445 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now