Google Answers Logo
View Question
 
Q: Creating a Web Form with a multiple data tables in Visual Web Developer 2005 ( No Answer,   0 Comments )
Question  
Subject: Creating a Web Form with a multiple data tables in Visual Web Developer 2005
Category: Computers > Programming
Asked by: tbonehwd-ga
List Price: $62.50
Posted: 22 Feb 2006 13:53 PST
Expires: 27 Feb 2006 09:59 PST
Question ID: 448523
I am trying to create a form where users can enter new Title
information, the title header information is being stored in a table
called Books. In addition to the information stored in Books I have
another table called Subjects the Subjects table has the BookID in it
as a foreign key, each book can have multiple subjects.

Tables
Books - BookID (varchar50) Primary Key
      - Title (varchar50)

Subjects - iSubjectID (int) Primary Key auto-increment
         - BookID (varchar50)
         - Subject (varchar50)

What I want to accomplish is when the form loads if the book has
subjects tied to it display them in a detailsview (dvSubject) with
paging turned on allowing the user to edit and delete however on
insert I do not want to make the user have to type the BookID it
should be able to pull it from dvBook. If when the form loads and does
not have any subject records tied to that book I would like dvSubject
to display with defaultmode=insert so users can add a subject if they
want to.

I have alot more fields to add but I wanted to keep this as simple as
possible and have been racking my brain on how to do this and I know
it can not be that hard, below is the code that I have so far for
this.

<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="BookEntry.aspx.vb" Inherits="BookEntry" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        &nbsp;&nbsp;
        <asp:ObjectDataSource ID="odsBook" runat="server"
InsertMethod="InsertBook"
OldValuesParameterFormatString="original_{0}"
            SelectMethod="GetByBookID"
TypeName="BooksTableAdapters.BooksTableAdapter"
UpdateMethod="UpdateBook" DeleteMethod="Delete">
            <UpdateParameters>
                <asp:Parameter Name="BookID" Type="String" />
                <asp:Parameter Name="Title" Type="String" />
                <asp:Parameter Name="Original_BookID" Type="String" />
            </UpdateParameters>
            <SelectParameters>
                <asp:QueryStringParameter Name="BookID" QueryStringField="BookID"
                    Type="String" />
            </SelectParameters>
            <InsertParameters>
                <asp:Parameter Name="BookID" Type="String" />
                <asp:Parameter Name="Title" Type="String" />
            </InsertParameters>
            <DeleteParameters>
                <asp:Parameter Name="Original_BookID" Type="String" />
            </DeleteParameters>
        </asp:ObjectDataSource>
        <asp:DetailsView ID="dvBook" runat="server"
AutoGenerateRows="False" DataKeyNames="BookID"
            DataSourceID="odsBook" Height="50px" Width="446px" >
            <Fields>
                <asp:BoundField DataField="BookID" HeaderText="BookID"
SortExpression="BookID" />
                <asp:BoundField DataField="Title" HeaderText="Title"
SortExpression="Title" />
                <asp:CommandField ShowEditButton="True"
ShowInsertButton="True" ShowDeleteButton="True" />
            </Fields>
        </asp:DetailsView>
        <asp:ObjectDataSource ID="odsSubject" runat="server"
DeleteMethod="DeleteSubject" InsertMethod="InsertSubject"
            OldValuesParameterFormatString="original_{0}"
SelectMethod="GetSubjectByBookID"
            TypeName="BooksTableAdapters.SubjectsTableAdapter"
UpdateMethod="UpdateSubject">
            <DeleteParameters>
                <asp:Parameter Name="Original_iSubjectID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="BookID" Type="String" />
                <asp:Parameter Name="Subject" Type="String" />
                <asp:Parameter Name="Original_iSubjectID" Type="Int32" />
            </UpdateParameters>
            <SelectParameters>
                <asp:ControlParameter ControlID="dvBook" Name="BookID"
PropertyName="SelectedValue"
                    Type="String" />
            </SelectParameters>
            <InsertParameters>
                <asp:Parameter Name="BookID" Type="String" />
                <asp:Parameter Name="Subject" Type="String" />
            </InsertParameters>
        </asp:ObjectDataSource>
        <asp:DetailsView ID="dvSubject" runat="server"
AllowPaging="True" AutoGenerateRows="False"
            DataKeyNames="iSubjectID" DataSourceID="odsSubject"
Height="50px" HorizontalAlign="Left"
            Width="445px">
            <Fields>
                <asp:BoundField DataField="iSubjectID"
HeaderText="iSubjectID" InsertVisible="False"
                    ReadOnly="True" SortExpression="iSubjectID" Visible="False" />
                <asp:BoundField DataField="BookID" HeaderText="BookID"
SortExpression="BookID" />
                <asp:BoundField DataField="Subject"
HeaderText="Subject" SortExpression="Subject" />
                <asp:CommandField ShowEditButton="True"
ShowDeleteButton="True" ShowInsertButton="True" />
            </Fields>
        </asp:DetailsView>
    </form>
</body>
</html>

Clarification of Question by tbonehwd-ga on 27 Feb 2006 09:59 PST
I found the answer to the foreign key issue so I thought I would post
this prior to canceling my question...

If you change the Update and Insert Parameters of odsSubject from:

<asp:Parameter Name="BookID" Type="String" />

to

<asp:ControlParameter ControlID="dvBook" Name="BookID"
PropertyName="SelectedValue" Type="String" />


this will save the user having to type in the BookId
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy