Solved

FormView control only displays one row of data

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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

734 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