problem on using grid view and detailsview in separate page

JTLO

New member
Joined
Sep 27, 2007
Messages
2
Programming Experience
Beginner
i have a gridview in a page called "Books.aspx" and a detailsview in another page called "Bookcollection.aspx".

when i click the "edit" in the page "Books.aspx", i want it link to page "BookCollection.aspx" to let me edit the data.

my problem is the data in the page "BookCollection.aspx" always in default, it not show the related data which i want to edit. What wrong for my code?

code in page "Books.aspx":

VB.NET:
<%@ 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">
           
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            DataKeyNames="No" DataSourceID="AccessDataSource1" AllowSorting="true" OnRowDeleted="GridView1_RowDeleted" >
            <Columns>
                <asp:BoundField DataField="No" HeaderText="No" ReadOnly="True" SortExpression="No" />
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                <asp:BoundField DataField="Author" HeaderText="Author" SortExpression="Author" />
                
               <asp:HyperLinkField Text="Edit" DataNavigateUrlFields="No" DataNavigateUrlFormatString="BookCollection.aspx?ID={0}" />
                <asp:CommandField ShowDeleteButton="true" />
            </Columns>
        </asp:GridView>
        <br />
        <center>
        <asp:HyperLink ID="HyperLink1" Text="Add New Book Collection..." NavigateUrl="~/Add.aspx" runat="server" />
        </center>
        
        
        <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="App_Data\bookcollection.mdb"
            SelectCommand="SELECT [No], [Title], [Author] FROM Books"
            DeleteCommand="DELETE FROM [Books] WHERE [No] = @No">
            
           
            <DeleteParameters>
                <asp:Parameter Name="No" Type="Int16" />
            </DeleteParameters>
            
           
        </asp:AccessDataSource>
        
        <asp:Label ID="ErrorMessageLabel" EnableViewState="false" runat="server" />
        
 </div>       
</asp:Content>


code in "bookcollection.aspx":

VB.NET:
<%@ 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">
          
              
       <center>
       <asp:DetailsView ID="DetailsView1"
           runat="server" AutoGenerateRows="False" DataKeyNames="No" DataSourceID="AccessDataSource2"
           Height="50px" Width="125px" defaultmode="edit" OnItemUpdated="DetailsView1_ItemUpdated" OnModeChanging="DetailsView1_ModeChanging" >
           <Fields>
               <asp:BoundField DataField="No" HeaderText="No" ReadOnly="True" SortExpression="No" />
               <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
               <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" />
               <asp:CommandField ShowEditButton="True" />
           </Fields>
       </asp:DetailsView>
       
       <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/bookcollection.mdb"
            SelectCommand="SELECT [No], [Title], [Author], [ISBN], [Publisher], [YearPublished], [Edition], [Remarks], [Photograph] FROM [Books] "
            UpdateCommand="UPDATE [Books] SET [Title]=@Title, [Author]=@Author, [ISBN]=@ISBN, [Publisher]=@Publisher, [YearPublished]=@YearPublished, [Edition]=@Edition, [Remarks]=@Remarks, [Photograph]=@Photograph) where [No]=@original_No">
    
         

         <UpdateParameters>
               <asp:Parameter Name="original_No" Type="Int16" />
               <asp:Parameter Name="Title" Type="String" />
               <asp:Parameter Name="Author" Type="String" />
               <asp:Parameter Name="ISBN" Type="String" />
               <asp:Parameter Name="Publisher" Type="String" />
               <asp:Parameter Name="YearPublished" Type="String" />
               <asp:Parameter Name="Edition" Type="String" />
               <asp:Parameter Name="Remarks" Type="String" />
               <asp:Parameter Name="Photograph" Type="Object" />
           </UpdateParameters>
           
           </asp:AccessDataSource>
       </center>
              <br />
   </div>
    
</asp:Content>
 
Back
Top