Results 1 to 2 of 2

Thread: using gridview and detailsview in separate page.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    using gridview and detailsview in separate page.

    i have a page called books.aspx which have the code as below:

    Code:
    <%@ Page Language="VB" MasterPageFile="~/Default.master" AutoEventWireup="false" CodeFile="Books.aspx.vb" Inherits="BookCollection" title="Untitled Page" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
    
        <div class="page" id="home">
            &nbsp; &nbsp;
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                DataKeyNames="No" DataSourceID="AccessDataSource1" EmptyDataText="There are no data records to display.">
                <Columns>
                    <asp:CommandField ShowEditButton="True" ShowSelectButton="True" />
                    <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                    <asp:BoundField DataField="Author" HeaderText="Author" SortExpression="Author" />
                    <asp:HyperLinkField Text="View" DataNavigateUrlFields="No" DataNavigateUrlFormatString="BookCollection.aspx?ID={0}" />
                </Columns>
            </asp:GridView>
            
           
            
            <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="App_Data\bookcollection.mdb"
                DeleteCommand="DELETE FROM `Books` WHERE `No` = ?" InsertCommand="INSERT INTO `Books` (`No`, `Title`, `Author`) VALUES (?, ?, ?)"
                SelectCommand="SELECT [No], Title, Author FROM Books" UpdateCommand="UPDATE `Books` SET `Title` = ?, `Author` = ? WHERE `No` = ?">
                <InsertParameters>
                    <asp:Parameter Name="No" Type="Int16" />
                    <asp:Parameter Name="Title" Type="String" />
                    <asp:Parameter Name="Author" Type="String" />
                </InsertParameters>
                <DeleteParameters>
                    <asp:Parameter Name="No" Type="Int16" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Title" Type="String" />
                    <asp:Parameter Name="Author" Type="String" />
                    <asp:Parameter Name="No" Type="Int16" />
                </UpdateParameters>
            </asp:AccessDataSource>
            
            
    </asp:Content>
    i have another page called bookcollection.aspx and code as below:

    Code:
    <%@ Page Language="VB" MasterPageFile="~/Default.master" AutoEventWireup="false" CodeFile="BookCollection.aspx.vb" Inherits="Books" title="Untitled Page" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
       <div class="page" id="home">
           <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="No" AllowPaging="true"
               DataSourceID="AccessDataSource2" Height="50px" Width="125px">
               <Fields>
                   <asp:BoundField DataField="No" HeaderText="No" ReadOnly="True" SortExpression="No" />
                   <asp:BoundField DataField="Author" HeaderText="Author" SortExpression="Author" />
                   <asp:BoundField DataField="ISBN" HeaderText="ISBN" SortExpression="ISBN" />
                   <asp:BoundField DataField="Publisher" HeaderText="Publisher" SortExpression="Publisher" />
                   <asp:BoundField DataField="YearPublished" HeaderText="YearPublished" SortExpression="YearPublished" />
                   <asp:BoundField DataField="Edition" HeaderText="Edition" SortExpression="Edition" />
                   <asp:BoundField DataField="Remarks" HeaderText="Remarks" SortExpression="Remarks" />
               </Fields>
           </asp:DetailsView>
           <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/bookcollection.mdb"
               SelectCommand="SELECT [No], Author, ISBN, Publisher, YearPublished, Edition, Remarks, Photograph FROM Books WHERE ([No] = ?)" OldValuesParameterFormatString="original_{0}">
               <SelectParameters>
                   <asp:QueryStringParameter DefaultValue="1" Name="No" QueryStringField="No" Type="Int16" />
               </SelectParameters>
           </asp:AccessDataSource>
           &nbsp; &nbsp;&nbsp;<br />
       </div>
        
    </asp:Content>
    i want show the details in "bookcollection.aspx" page when i click the "view" in "books.aspx". But , with code above. i can't get the result. what wrong for my code.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: using gridview and detailsview in separate page.

    You've set up your hyperlink field.

    BookCollection.aspx?ID={0}

    Does the hyperlink render properly with correct IDs?

    When you then click on the link and go to BookCollection.aspx, how are you actually getting the ID? The SelectCommand of your datasource needs to know the ID that it is supposed to be dealing with. For that, you need to use Request.QueryString(), and pass it to the SelectCommand.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width