How-to link 2 Detailsview

How-to link 2 Detailsview

Post by YnJ1bm » Thu, 20 Jul 2006 05:51:02

Sorry for a very basic question. I'm new in ASP.NET programming .
Is there a way to link 2 different DetailsView controls, each one bound to a
differet SQLServer table. Can I get an example in VB.NET?

If I use a DropdownList instead of the first DetailsView I can reference the
selected value as <asp:parameter .... PropertyName="SelectedValue" ...
But what about DetailsView controls?


How-to link 2 Detailsview

Post by stchen » Thu, 20 Jul 2006 13:04:15

i Bruno,

Welcome to the ASP.NET newsgroup.

From your description, I understand you're wondering how to link two
detailsView so as to make one detailsView use another DetailsView's current
DataItem's value as input parameter, correct?

As for this question, I think it is certainly doable, however, how we do it
depends on the column/field you want reference in the source DetailsView(as
parameter). Is that field/column in the DetailsView (you want to query as
input parameter for another DetailsView) the primarykey column? If so, we
can also use the "DetailsView.SelectedValue" property to reference the
current selected Row's primarykey value (just like the way we do for
DropDownList). For example, here is a simple page which contains a GridView
and DetailsView, the GridView use DetailsView's current selected Row's Key
value as input parameter(in DataSource);

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName] FROM
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [ProductID], [ProductName], [UnitPrice], [CategoryID]
FROM [Products] WHERE ([CategoryID] = @CategoryID)">
<asp:ControlParameter ControlID="DetailsView1"
Name="CategoryID" PropertyName="SelectedValue"
Type="Int32" />

<table >
<asp:DetailsView ID="DetailsView1" runat="server"
AllowPaging="True" AutoGenerateRows="False" DataKeyNames="CategoryID"
Height="50px" Width="125px">
<asp:BoundField DataField="CategoryID"
HeaderText="CategoryID" InsertVisible="False"
ReadOnly="True" SortExpression="CategoryID" />
<asp:BoundField DataField="CategoryName"
HeaderText="CategoryName" SortExpression="CategoryName" />

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="ProductID"
<asp:BoundField DataField="ProductID"
HeaderText="ProductID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName"
HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="UnitPrice"
HeaderText="UnitPrice" SortExpression="UnitPrice" />
<asp:BoundField DataField="CategoryID"
HeaderText="CategoryID" SortExpression="CategoryID" />

If the column/field you want to reference is not the primary key column,
the "SelectedValue" approach won't work. In such case, we need to use code
and programmatica

How-to link 2 Detailsview

Post by YnJ1bm » Mon, 24 Jul 2006 16:13:02

hat help me.
Thank you very much.
Have a nice day!

"Steven Cheng[MSFT]" wrote: