By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,414 Members | 2,939 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,414 IT Pros & Developers. It's quick & easy.

Populating FormView (asp.net 2.0 using vb.net)

P: n/a
Hello,

I am creating a form for users to enter information about a lab and the
members of the lab. I have one form (FormView) that they use to enter
information about that lab. The keyvalue is "LabLocation_ID". With an
existing lab, they then need to add the members for that lab. So, what I am
trying to do is the following. With the FormView of the Lab open, the user
will click a button to open a FormView (InsertMode) and add a new user. My
question is, how do I copy the "LabLocation_ID" from the "Lab" FormView to
the "Member" FormView?

table structure (tblLabLocation_Member)
LabLocation_ID (varchar 200)
Member_ID (varchar 200)

--
Thanks in advance,

sck10
Dec 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Sck10,

Welcome to ASPNET newsgroup.
As for the displaying master/details structure datas through the ASP.NET
2.0 databound controls, I think you can consider the following means;

use the FormView to bound to the Lab table(through a SqlDataSource), and
set the FormView's DataKeyNames to the Lab table's primary Key, and then,
declare another DataSource which select data from Member table through the
Lab_Member relation table....
we can declare a select parameter (for where clause ) in the
SqlDataSource's SelectCommand , and set the select parameter as
ControlParameter which pointed to the Lab FormView's SelectedValue
property.... After that, we can bound the second datasource to a certain
GridView or another Formview /DetailsView...... Thus, the relation
between the master/details datas is established....
Below is a sample Page which use a FormView and a GridView to display
Master/Detail data from the Northwind database's Orders and OrderDetails
tables.....

==================================
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:LocalNorthWind %>"
DeleteCommand="DELETE FROM [Orders] WHERE [OrderID] = @OrderID"
InsertCommand="INSERT INTO [Orders] ([CustomerID], [EmployeeID],
[OrderDate]) VALUES (@CustomerID, @EmployeeID, @OrderDate)"
SelectCommand="SELECT [OrderID], [CustomerID], [EmployeeID],
[OrderDate] FROM [Orders]"
UpdateCommand="UPDATE [Orders] SET [CustomerID] = @CustomerID,
[EmployeeID] = @EmployeeID, [OrderDate] = @OrderDate WHERE [OrderID] =
@OrderID">
<DeleteParameters>
<asp:Parameter Name="OrderID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="CustomerID" Type="String" />
<asp:Parameter Name="EmployeeID" Type="Int32" />
<asp:Parameter Name="OrderDate" Type="DateTime" />
<asp:Parameter Name="OrderID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="CustomerID" Type="String" />
<asp:Parameter Name="EmployeeID" Type="Int32" />
<asp:Parameter Name="OrderDate" Type="DateTime" />
</InsertParameters>
</asp:SqlDataSource>

</div>
<asp:FormView ID="FormView1" runat="server" AllowPaging="True"
DataKeyNames="OrderID"
DataSourceID="SqlDataSource1">
<EditItemTemplate>
OrderID:
<asp:Label ID="OrderIDLabel1" runat="server" Text='<%#
Eval("OrderID") %>'></asp:Label><br />
CustomerID:
<asp:TextBox ID="CustomerIDTextBox" runat="server"
Text='<%# Bind("CustomerID") %>'>
</asp:TextBox><br />
EmployeeID:
<asp:TextBox ID="EmployeeIDTextBox" runat="server"
Text='<%# Bind("EmployeeID") %>'>
</asp:TextBox><br />
OrderDate:
<asp:TextBox ID="OrderDateTextBox" runat="server" Text='<%#
Bind("OrderDate") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
CustomerID:
<asp:TextBox ID="CustomerIDTextBox" runat="server"
Text='<%# Bind("CustomerID") %>'>
</asp:TextBox><br />
EmployeeID:
<asp:TextBox ID="EmployeeIDTextBox" runat="server"
Text='<%# Bind("EmployeeID") %>'>
</asp:TextBox><br />
OrderDate:
<asp:TextBox ID="OrderDateTextBox" runat="server" Text='<%#
Bind("OrderDate") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="InsertButton" runat="server"
CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
OrderID:
<asp:Label ID="OrderIDLabel" runat="server" Text='<%#
Eval("OrderID") %>'></asp:Label><br />
CustomerID:
<asp:Label ID="CustomerIDLabel" runat="server" Text='<%#
Bind("CustomerID") %>'>
</asp:Label><br />
EmployeeID:
<asp:Label ID="EmployeeIDLabel" runat="server" Text='<%#
Bind("EmployeeID") %>'>
</asp:Label><br />
OrderDate:
<asp:Label ID="OrderDateLabel" runat="server" Text='<%#
Bind("OrderDate") %>'></asp:Label><br />
<asp:LinkButton ID="EditButton" runat="server"
CausesValidation="False" CommandName="Edit"
Text="Edit">
</asp:LinkButton>
<asp:LinkButton ID="DeleteButton" runat="server"
CausesValidation="False" CommandName="Delete"
Text="Delete">
</asp:LinkButton>
<asp:LinkButton ID="NewButton" runat="server"
CausesValidation="False" CommandName="New"
Text="New">
</asp:LinkButton>
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:LocalNorthWind %>"
DeleteCommand="DELETE FROM [Order Details] WHERE [OrderID] =
@OrderID AND [ProductID] = @ProductID"
InsertCommand="INSERT INTO [Order Details] ([OrderID],
[ProductID], [Discount], [Quantity], [UnitPrice]) VALUES (@OrderID,
@ProductID, @Discount, @Quantity, @UnitPrice)"
SelectCommand="SELECT [OrderID], [ProductID], [Discount],
[Quantity], [UnitPrice] FROM [Order Details] WHERE ([OrderID] = @OrderID)"
UpdateCommand="UPDATE [Order Details] SET [Discount] =
@Discount, [Quantity] = @Quantity, [UnitPrice] = @UnitPrice WHERE [OrderID]
= @OrderID AND [ProductID] = @ProductID">
<DeleteParameters>
<asp:Parameter Name="OrderID" Type="Int32" />
<asp:Parameter Name="ProductID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Discount" Type="Single" />
<asp:Parameter Name="Quantity" Type="Int16" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
<asp:Parameter Name="OrderID" Type="Int32" />
<asp:Parameter Name="ProductID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="FormView1" Name="OrderID"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="OrderID" Type="Int32" />
<asp:Parameter Name="ProductID" Type="Int32" />
<asp:Parameter Name="Discount" Type="Single" />
<asp:Parameter Name="Quantity" Type="Int16" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
</InsertParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="OrderID,ProductID"
DataSourceID="SqlDataSource2">
<Columns>
<asp:CommandField ShowEditButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="OrderID" HeaderText="OrderID"
ReadOnly="True" SortExpression="OrderID" />
<asp:BoundField DataField="ProductID"
HeaderText="ProductID" ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="Discount" HeaderText="Discount"
SortExpression="Discount" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity"
SortExpression="Quantity" />
<asp:BoundField DataField="UnitPrice"
HeaderText="UnitPrice" SortExpression="UnitPrice" />
</Columns>
</asp:GridView>
</form>
========================

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "sck10" <sc***@online.nospam>
| Subject: Populating FormView (asp.net 2.0 using vb.net)
| Date: Thu, 22 Dec 2005 17:57:59 -0600
| Lines: 21
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| Message-ID: <eS**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 189.202.185.135.in-addr.arpa 135.185.202.189
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:366683
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hello,
|
| I am creating a form for users to enter information about a lab and the
| members of the lab. I have one form (FormView) that they use to enter
| information about that lab. The keyvalue is "LabLocation_ID". With an
| existing lab, they then need to add the members for that lab. So, what I
am
| trying to do is the following. With the FormView of the Lab open, the
user
| will click a button to open a FormView (InsertMode) and add a new user.
My
| question is, how do I copy the "LabLocation_ID" from the "Lab" FormView to
| the "Member" FormView?
|
| table structure (tblLabLocation_Member)
| LabLocation_ID (varchar 200)
| Member_ID (varchar 200)
|
| --
| Thanks in advance,
|
| sck10
|
|
|

Dec 23 '05 #2

P: n/a
Hi Steven,

I'd like to do something like this, but my problem is the fact that I have a
list of the members and have to add some of them to a new lab. I've done
something similar in vs 2003 with the strongly typed Dataset. This solution
helps me to save all changes only after final submit. Is there a better way
to do so in vs 2005.

Thanks,

Vlad Sadilov

"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:QZ**************@TK2MSFTNGXA02.phx.gbl...
Hi Sck10,

Welcome to ASPNET newsgroup.
As for the displaying master/details structure datas through the ASP.NET
2.0 databound controls, I think you can consider the following means;

use the FormView to bound to the Lab table(through a SqlDataSource), and
set the FormView's DataKeyNames to the Lab table's primary Key, and
then,
declare another DataSource which select data from Member table through the
Lab_Member relation table....
we can declare a select parameter (for where clause ) in the
SqlDataSource's SelectCommand , and set the select parameter as
ControlParameter which pointed to the Lab FormView's SelectedValue
property.... After that, we can bound the second datasource to a certain
GridView or another Formview /DetailsView...... Thus, the relation
between the master/details datas is established....
Below is a sample Page which use a FormView and a GridView to display
Master/Detail data from the Northwind database's Orders and OrderDetails
tables.....

==================================
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:LocalNorthWind %>"
DeleteCommand="DELETE FROM [Orders] WHERE [OrderID] = @OrderID"
InsertCommand="INSERT INTO [Orders] ([CustomerID], [EmployeeID],
[OrderDate]) VALUES (@CustomerID, @EmployeeID, @OrderDate)"
SelectCommand="SELECT [OrderID], [CustomerID], [EmployeeID],
[OrderDate] FROM [Orders]"
UpdateCommand="UPDATE [Orders] SET [CustomerID] = @CustomerID,
[EmployeeID] = @EmployeeID, [OrderDate] = @OrderDate WHERE [OrderID] =
@OrderID">
<DeleteParameters>
<asp:Parameter Name="OrderID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="CustomerID" Type="String" />
<asp:Parameter Name="EmployeeID" Type="Int32" />
<asp:Parameter Name="OrderDate" Type="DateTime" />
<asp:Parameter Name="OrderID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="CustomerID" Type="String" />
<asp:Parameter Name="EmployeeID" Type="Int32" />
<asp:Parameter Name="OrderDate" Type="DateTime" />
</InsertParameters>
</asp:SqlDataSource>

</div>
<asp:FormView ID="FormView1" runat="server" AllowPaging="True"
DataKeyNames="OrderID"
DataSourceID="SqlDataSource1">
<EditItemTemplate>
OrderID:
<asp:Label ID="OrderIDLabel1" runat="server" Text='<%#
Eval("OrderID") %>'></asp:Label><br />
CustomerID:
<asp:TextBox ID="CustomerIDTextBox" runat="server"
Text='<%# Bind("CustomerID") %>'>
</asp:TextBox><br />
EmployeeID:
<asp:TextBox ID="EmployeeIDTextBox" runat="server"
Text='<%# Bind("EmployeeID") %>'>
</asp:TextBox><br />
OrderDate:
<asp:TextBox ID="OrderDateTextBox" runat="server" Text='<%#
Bind("OrderDate") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
CustomerID:
<asp:TextBox ID="CustomerIDTextBox" runat="server"
Text='<%# Bind("CustomerID") %>'>
</asp:TextBox><br />
EmployeeID:
<asp:TextBox ID="EmployeeIDTextBox" runat="server"
Text='<%# Bind("EmployeeID") %>'>
</asp:TextBox><br />
OrderDate:
<asp:TextBox ID="OrderDateTextBox" runat="server" Text='<%#
Bind("OrderDate") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="InsertButton" runat="server"
CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
OrderID:
<asp:Label ID="OrderIDLabel" runat="server" Text='<%#
Eval("OrderID") %>'></asp:Label><br />
CustomerID:
<asp:Label ID="CustomerIDLabel" runat="server" Text='<%#
Bind("CustomerID") %>'>
</asp:Label><br />
EmployeeID:
<asp:Label ID="EmployeeIDLabel" runat="server" Text='<%#
Bind("EmployeeID") %>'>
</asp:Label><br />
OrderDate:
<asp:Label ID="OrderDateLabel" runat="server" Text='<%#
Bind("OrderDate") %>'></asp:Label><br />
<asp:LinkButton ID="EditButton" runat="server"
CausesValidation="False" CommandName="Edit"
Text="Edit">
</asp:LinkButton>
<asp:LinkButton ID="DeleteButton" runat="server"
CausesValidation="False" CommandName="Delete"
Text="Delete">
</asp:LinkButton>
<asp:LinkButton ID="NewButton" runat="server"
CausesValidation="False" CommandName="New"
Text="New">
</asp:LinkButton>
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:LocalNorthWind %>"
DeleteCommand="DELETE FROM [Order Details] WHERE [OrderID] =
@OrderID AND [ProductID] = @ProductID"
InsertCommand="INSERT INTO [Order Details] ([OrderID],
[ProductID], [Discount], [Quantity], [UnitPrice]) VALUES (@OrderID,
@ProductID, @Discount, @Quantity, @UnitPrice)"
SelectCommand="SELECT [OrderID], [ProductID], [Discount],
[Quantity], [UnitPrice] FROM [Order Details] WHERE ([OrderID] = @OrderID)"
UpdateCommand="UPDATE [Order Details] SET [Discount] =
@Discount, [Quantity] = @Quantity, [UnitPrice] = @UnitPrice WHERE
[OrderID]
= @OrderID AND [ProductID] = @ProductID">
<DeleteParameters>
<asp:Parameter Name="OrderID" Type="Int32" />
<asp:Parameter Name="ProductID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Discount" Type="Single" />
<asp:Parameter Name="Quantity" Type="Int16" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
<asp:Parameter Name="OrderID" Type="Int32" />
<asp:Parameter Name="ProductID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="FormView1" Name="OrderID"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="OrderID" Type="Int32" />
<asp:Parameter Name="ProductID" Type="Int32" />
<asp:Parameter Name="Discount" Type="Single" />
<asp:Parameter Name="Quantity" Type="Int16" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
</InsertParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="OrderID,ProductID"
DataSourceID="SqlDataSource2">
<Columns>
<asp:CommandField ShowEditButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="OrderID" HeaderText="OrderID"
ReadOnly="True" SortExpression="OrderID" />
<asp:BoundField DataField="ProductID"
HeaderText="ProductID" ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="Discount" HeaderText="Discount"
SortExpression="Discount" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity"
SortExpression="Quantity" />
<asp:BoundField DataField="UnitPrice"
HeaderText="UnitPrice" SortExpression="UnitPrice" />
</Columns>
</asp:GridView>
</form>
========================

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "sck10" <sc***@online.nospam>
| Subject: Populating FormView (asp.net 2.0 using vb.net)
| Date: Thu, 22 Dec 2005 17:57:59 -0600
| Lines: 21
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| Message-ID: <eS**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 189.202.185.135.in-addr.arpa 135.185.202.189
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:366683
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hello,
|
| I am creating a form for users to enter information about a lab and the
| members of the lab. I have one form (FormView) that they use to enter
| information about that lab. The keyvalue is "LabLocation_ID". With an
| existing lab, they then need to add the members for that lab. So, what
I
am
| trying to do is the following. With the FormView of the Lab open, the
user
| will click a button to open a FormView (InsertMode) and add a new user.
My
| question is, how do I copy the "LabLocation_ID" from the "Lab" FormView
to
| the "Member" FormView?
|
| table structure (tblLabLocation_Member)
| LabLocation_ID (varchar 200)
| Member_ID (varchar 200)
|
| --
| Thanks in advance,
|
| sck10
|
|
|

Dec 25 '05 #3

P: n/a
Hi Vlad,

If you want complex customization, the typed DataSet components are still
available in asp.net/ado.net 2.0 and they're even enhanced by the new
DataSet/TableAdapter components:

#TableAdapter Overview
http://msdn2.microsoft.com/en-us/library/bz9tthwx.aspx

#How to: Directly Access the Database with a TableAdapter
http://msdn2.microsoft.com/en-us/library/ms171935.aspx

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Vlad Sadilov" <v_*******@hotmail.com>
| References: <eS**************@TK2MSFTNGP12.phx.gbl>
<QZ**************@TK2MSFTNGXA02.phx.gbl>
| Subject: Re: Populating FormView (asp.net 2.0 using vb.net)
| Date: Sun, 25 Dec 2005 01:37:41 +0100
| Lines: 258
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
| X-RFC2646: Format=Flowed; Original
| Message-ID: <#k**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: host107-73.pool80104.interbusiness.it 80.104.73.107
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:366962
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi Steven,
|
| I'd like to do something like this, but my problem is the fact that I
have a
| list of the members and have to add some of them to a new lab. I've done
| something similar in vs 2003 with the strongly typed Dataset. This
solution
| helps me to save all changes only after final submit. Is there a better
way
| to do so in vs 2005.
|
| Thanks,
|
| Vlad Sadilov
|
| "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| news:QZ**************@TK2MSFTNGXA02.phx.gbl...
| > Hi Sck10,
| >
| > Welcome to ASPNET newsgroup.
| > As for the displaying master/details structure datas through the ASP.NET
| > 2.0 databound controls, I think you can consider the following means;
| >
| > use the FormView to bound to the Lab table(through a SqlDataSource), and
| > set the FormView's DataKeyNames to the Lab table's primary Key, and
| > then,
| > declare another DataSource which select data from Member table through
the
| > Lab_Member relation table....
| > we can declare a select parameter (for where clause ) in the
| > SqlDataSource's SelectCommand , and set the select parameter as
| > ControlParameter which pointed to the Lab FormView's SelectedValue
| > property.... After that, we can bound the second datasource to a
certain
| > GridView or another Formview /DetailsView...... Thus, the relation
| > between the master/details datas is established....
| > Below is a sample Page which use a FormView and a GridView to display
| > Master/Detail data from the Northwind database's Orders and
OrderDetails
| > tables.....
| >
| > ==================================
| > <form id="form1" runat="server">
| > <div>
| > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
| > ConnectionString="<%$ ConnectionStrings:LocalNorthWind %>"
| > DeleteCommand="DELETE FROM [Orders] WHERE [OrderID] =
@OrderID"
| > InsertCommand="INSERT INTO [Orders] ([CustomerID], [EmployeeID],
| > [OrderDate]) VALUES (@CustomerID, @EmployeeID, @OrderDate)"
| > SelectCommand="SELECT [OrderID], [CustomerID], [EmployeeID],
| > [OrderDate] FROM [Orders]"
| > UpdateCommand="UPDATE [Orders] SET [CustomerID] =
@CustomerID,
| > [EmployeeID] = @EmployeeID, [OrderDate] = @OrderDate WHERE [OrderID] =
| > @OrderID">
| > <DeleteParameters>
| > <asp:Parameter Name="OrderID" Type="Int32" />
| > </DeleteParameters>
| > <UpdateParameters>
| > <asp:Parameter Name="CustomerID" Type="String" />
| > <asp:Parameter Name="EmployeeID" Type="Int32" />
| > <asp:Parameter Name="OrderDate" Type="DateTime" />
| > <asp:Parameter Name="OrderID" Type="Int32" />
| > </UpdateParameters>
| > <InsertParameters>
| > <asp:Parameter Name="CustomerID" Type="String" />
| > <asp:Parameter Name="EmployeeID" Type="Int32" />
| > <asp:Parameter Name="OrderDate" Type="DateTime" />
| > </InsertParameters>
| > </asp:SqlDataSource>
| >
| > </div>
| > <asp:FormView ID="FormView1" runat="server" AllowPaging="True"
| > DataKeyNames="OrderID"
| > DataSourceID="SqlDataSource1">
| > <EditItemTemplate>
| > OrderID:
| > <asp:Label ID="OrderIDLabel1" runat="server" Text='<%#
| > Eval("OrderID") %>'></asp:Label><br />
| > CustomerID:
| > <asp:TextBox ID="CustomerIDTextBox" runat="server"
| > Text='<%# Bind("CustomerID") %>'>
| > </asp:TextBox><br />
| > EmployeeID:
| > <asp:TextBox ID="EmployeeIDTextBox" runat="server"
| > Text='<%# Bind("EmployeeID") %>'>
| > </asp:TextBox><br />
| > OrderDate:
| > <asp:TextBox ID="OrderDateTextBox" runat="server"
Text='<%#
| > Bind("OrderDate") %>'>
| > </asp:TextBox><br />
| > <asp:LinkButton ID="UpdateButton" runat="server"
| > CausesValidation="True" CommandName="Update"
| > Text="Update">
| > </asp:LinkButton>
| > <asp:LinkButton ID="UpdateCancelButton" runat="server"
| > CausesValidation="False" CommandName="Cancel"
| > Text="Cancel">
| > </asp:LinkButton>
| > </EditItemTemplate>
| > <InsertItemTemplate>
| > CustomerID:
| > <asp:TextBox ID="CustomerIDTextBox" runat="server"
| > Text='<%# Bind("CustomerID") %>'>
| > </asp:TextBox><br />
| > EmployeeID:
| > <asp:TextBox ID="EmployeeIDTextBox" runat="server"
| > Text='<%# Bind("EmployeeID") %>'>
| > </asp:TextBox><br />
| > OrderDate:
| > <asp:TextBox ID="OrderDateTextBox" runat="server"
Text='<%#
| > Bind("OrderDate") %>'>
| > </asp:TextBox><br />
| > <asp:LinkButton ID="InsertButton" runat="server"
| > CausesValidation="True" CommandName="Insert"
| > Text="Insert">
| > </asp:LinkButton>
| > <asp:LinkButton ID="InsertCancelButton" runat="server"
| > CausesValidation="False" CommandName="Cancel"
| > Text="Cancel">
| > </asp:LinkButton>
| > </InsertItemTemplate>
| > <ItemTemplate>
| > OrderID:
| > <asp:Label ID="OrderIDLabel" runat="server" Text='<%#
| > Eval("OrderID") %>'></asp:Label><br />
| > CustomerID:
| > <asp:Label ID="CustomerIDLabel" runat="server" Text='<%#
| > Bind("CustomerID") %>'>
| > </asp:Label><br />
| > EmployeeID:
| > <asp:Label ID="EmployeeIDLabel" runat="server" Text='<%#
| > Bind("EmployeeID") %>'>
| > </asp:Label><br />
| > OrderDate:
| > <asp:Label ID="OrderDateLabel" runat="server" Text='<%#
| > Bind("OrderDate") %>'></asp:Label><br />
| > <asp:LinkButton ID="EditButton" runat="server"
| > CausesValidation="False" CommandName="Edit"
| > Text="Edit">
| > </asp:LinkButton>
| > <asp:LinkButton ID="DeleteButton" runat="server"
| > CausesValidation="False" CommandName="Delete"
| > Text="Delete">
| > </asp:LinkButton>
| > <asp:LinkButton ID="NewButton" runat="server"
| > CausesValidation="False" CommandName="New"
| > Text="New">
| > </asp:LinkButton>
| > </ItemTemplate>
| > </asp:FormView>
| > <asp:SqlDataSource ID="SqlDataSource2" runat="server"
| > ConnectionString="<%$ ConnectionStrings:LocalNorthWind %>"
| > DeleteCommand="DELETE FROM [Order Details] WHERE [OrderID] =
| > @OrderID AND [ProductID] = @ProductID"
| > InsertCommand="INSERT INTO [Order Details] ([OrderID],
| > [ProductID], [Discount], [Quantity], [UnitPrice]) VALUES (@OrderID,
| > @ProductID, @Discount, @Quantity, @UnitPrice)"
| > SelectCommand="SELECT [OrderID], [ProductID], [Discount],
| > [Quantity], [UnitPrice] FROM [Order Details] WHERE ([OrderID] =
@OrderID)"
| > UpdateCommand="UPDATE [Order Details] SET [Discount] =
| > @Discount, [Quantity] = @Quantity, [UnitPrice] = @UnitPrice WHERE
| > [OrderID]
| > = @OrderID AND [ProductID] = @ProductID">
| > <DeleteParameters>
| > <asp:Parameter Name="OrderID" Type="Int32" />
| > <asp:Parameter Name="ProductID" Type="Int32" />
| > </DeleteParameters>
| > <UpdateParameters>
| > <asp:Parameter Name="Discount" Type="Single" />
| > <asp:Parameter Name="Quantity" Type="Int16" />
| > <asp:Parameter Name="UnitPrice" Type="Decimal" />
| > <asp:Parameter Name="OrderID" Type="Int32" />
| > <asp:Parameter Name="ProductID" Type="Int32" />
| > </UpdateParameters>
| > <SelectParameters>
| > <asp:ControlParameter ControlID="FormView1"
Name="OrderID"
| > PropertyName="SelectedValue"
| > Type="Int32" />
| > </SelectParameters>
| > <InsertParameters>
| > <asp:Parameter Name="OrderID" Type="Int32" />
| > <asp:Parameter Name="ProductID" Type="Int32" />
| > <asp:Parameter Name="Discount" Type="Single" />
| > <asp:Parameter Name="Quantity" Type="Int16" />
| > <asp:Parameter Name="UnitPrice" Type="Decimal" />
| > </InsertParameters>
| > </asp:SqlDataSource>
| > <asp:GridView ID="GridView1" runat="server"
| > AutoGenerateColumns="False" DataKeyNames="OrderID,ProductID"
| > DataSourceID="SqlDataSource2">
| > <Columns>
| > <asp:CommandField ShowEditButton="True"
| > ShowSelectButton="True" />
| > <asp:BoundField DataField="OrderID" HeaderText="OrderID"
| > ReadOnly="True" SortExpression="OrderID" />
| > <asp:BoundField DataField="ProductID"
| > HeaderText="ProductID" ReadOnly="True" SortExpression="ProductID" />
| > <asp:BoundField DataField="Discount"
HeaderText="Discount"
| > SortExpression="Discount" />
| > <asp:BoundField DataField="Quantity"
HeaderText="Quantity"
| > SortExpression="Quantity" />
| > <asp:BoundField DataField="UnitPrice"
| > HeaderText="UnitPrice" SortExpression="UnitPrice" />
| > </Columns>
| > </asp:GridView>
| > </form>
| > ========================
| >
| > Hope helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| > --------------------
| > | From: "sck10" <sc***@online.nospam>
| > | Subject: Populating FormView (asp.net 2.0 using vb.net)
| > | Date: Thu, 22 Dec 2005 17:57:59 -0600
| > | Lines: 21
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| > | Message-ID: <eS**************@TK2MSFTNGP12.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: 189.202.185.135.in-addr.arpa 135.185.202.189
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:366683
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Hello,
| > |
| > | I am creating a form for users to enter information about a lab and
the
| > | members of the lab. I have one form (FormView) that they use to enter
| > | information about that lab. The keyvalue is "LabLocation_ID". With
an
| > | existing lab, they then need to add the members for that lab. So,
what
| > I
| > am
| > | trying to do is the following. With the FormView of the Lab open, the
| > user
| > | will click a button to open a FormView (InsertMode) and add a new
user.
| > My
| > | question is, how do I copy the "LabLocation_ID" from the "Lab"
FormView
| > to
| > | the "Member" FormView?
| > |
| > | table structure (tblLabLocation_Member)
| > | LabLocation_ID (varchar 200)
| > | Member_ID (varchar 200)
| > |
| > | --
| > | Thanks in advance,
| > |
| > | sck10
| > |
| > |
| > |
| >
|
|
|

Dec 26 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.