Solved

FormView control only displays one row of data

Posted on 2010-08-17
2
477 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

705 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