Itemtemplace and many to one dropdown example wanted

T

TdarTdar

Where can i find an expample of a item template that does the following

example of detailsview


name: Jack
City: 2342
State: 1


I want to change the city field I assume using Itemtemplate, and have
it link to a city table(another table) as a dropdown to display the city
name.
 
S

Steven Cheng[MSFT]

Hi Tdar,

Welcome.
Regarding on the question you mentioned, do you mean that you want to
display one of the column in DetailsView as a DropDownList and the
dropdownlist's items will be filled by data retrieved from another database
table?

If so, a simple means is add an another DataSource control which connect to
the data table that contains the DropDownList's items data.... Then, in
our main DataBound control(DetailsView?), we add a dropdownlist and set
its datasourceID to the new datasource control and bind its selectedValue
to the original databound value ......

To make it clear, here is a simple example which display the Product
table's data in a DetailsView control, and it contains one column which
display the Category through a DropDownList....

==========aspx=============
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [ProductID], [ProductName], [CategoryID]
FROM [Products]" DeleteCommand="DELETE FROM [Products] WHERE [ProductID] =
@ProductID" InsertCommand="INSERT INTO [Products] ([ProductName],
[CategoryID]) VALUES (@ProductName, @CategoryID)" UpdateCommand="UPDATE
[Products] SET [ProductName] = @ProductName, [CategoryID] = @CategoryID
WHERE [ProductID] = @ProductID">
<DeleteParameters>
<asp:parameter Name="ProductID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="ProductName" Type="String" />
<asp:parameter Name="CategoryID" Type="Int32" />
<asp:parameter Name="ProductID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="ProductName" Type="String" />
<asp:parameter Name="CategoryID" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName] FROM
[Categories]"></asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataKeyNames="ProductID"
DataSourceID="SqlDataSource1" Height="50px" Width="125px"
AllowPaging="True">
<Fields>
<asp:BoundField DataField="ProductID"
HeaderText="ProductID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName"
HeaderText="ProductName" SortExpression="ProductName" />
<asp:TemplateField HeaderText="CategoryID"
SortExpression="CategoryID">
<EditItemTemplate>
&nbsp;<asp:DropDownList ID="DropDownList1"
runat="server" DataSourceID="SqlDataSource2"
DataTextField="CategoryName"
DataValueField="CategoryID" SelectedValue='<%# Bind("CategoryID") %>'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("CategoryID") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
&nbsp;<asp:DropDownList ID="DropDownList2"
runat="server" DataSourceID="SqlDataSource2"
DataTextField="CategoryName"
DataValueField="CategoryID" Enabled="False" SelectedValue='<%#
Bind("CategoryID") %>'>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
</div>
</form>
</body>
</html>
=======================

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.)







--------------------
| Thread-Topic: Itemtemplace and many to one dropdown example wanted
| thread-index: AcYeKy7odVEPNOMCTeO27jfTJ/6shA==
| X-WBNR-Posting-Host: 65.35.95.187
| From: "=?Utf-8?B?VGRhclRkYXI=?=" <[email protected]>
| Subject: Itemtemplace and many to one dropdown example wanted
| Date: Fri, 20 Jan 2006 17:37:04 -0800
| Lines: 14
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:32702
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Where can i find an expample of a item template that does the following
|
| example of detailsview
|
|
| name: Jack
| City: 2342
| State: 1
|
|
| I want to change the city field I assume using Itemtemplate, and have
| it link to a city table(another table) as a dropdown to display the city
| name.
|
|
 
T

TdarTdar

Hi,
Thanks that helped, but how to a change one dropdown contents based on
anothers current selection.

as in selected state is "FL"

so the cities dropdown in edit mode should only show "Citys" in "FL"

I tried this but get an error:
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$
ConnectionStrings:SilverQueen_Main_SystemConnectionString1 %>"
SelectCommand="SELECT [StateKey], [StateName], [StateCode] FROM
[State] where StateKey = <%# Bind("StateKey") %> Order by
[StateName]"></asp:SqlDataSource>

I guess the bind statement is not valid at that time of form loading.

Tdar



Steven Cheng said:
Hi Tdar,

Welcome.
Regarding on the question you mentioned, do you mean that you want to
display one of the column in DetailsView as a DropDownList and the
dropdownlist's items will be filled by data retrieved from another database
table?

If so, a simple means is add an another DataSource control which connect to
the data table that contains the DropDownList's items data.... Then, in
our main DataBound control(DetailsView?), we add a dropdownlist and set
its datasourceID to the new datasource control and bind its selectedValue
to the original databound value ......

To make it clear, here is a simple example which display the Product
table's data in a DetailsView control, and it contains one column which
display the Category through a DropDownList....

==========aspx=============
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [ProductID], [ProductName], [CategoryID]
FROM [Products]" DeleteCommand="DELETE FROM [Products] WHERE [ProductID] =
@ProductID" InsertCommand="INSERT INTO [Products] ([ProductName],
[CategoryID]) VALUES (@ProductName, @CategoryID)" UpdateCommand="UPDATE
[Products] SET [ProductName] = @ProductName, [CategoryID] = @CategoryID
WHERE [ProductID] = @ProductID">
<DeleteParameters>
<asp:parameter Name="ProductID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="ProductName" Type="String" />
<asp:parameter Name="CategoryID" Type="Int32" />
<asp:parameter Name="ProductID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="ProductName" Type="String" />
<asp:parameter Name="CategoryID" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName] FROM
[Categories]"></asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataKeyNames="ProductID"
DataSourceID="SqlDataSource1" Height="50px" Width="125px"
AllowPaging="True">
<Fields>
<asp:BoundField DataField="ProductID"
HeaderText="ProductID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName"
HeaderText="ProductName" SortExpression="ProductName" />
<asp:TemplateField HeaderText="CategoryID"
SortExpression="CategoryID">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1"
runat="server" DataSourceID="SqlDataSource2"
DataTextField="CategoryName"
DataValueField="CategoryID" SelectedValue='<%# Bind("CategoryID") %>'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("CategoryID") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="DropDownList2"
runat="server" DataSourceID="SqlDataSource2"
DataTextField="CategoryName"
DataValueField="CategoryID" Enabled="False" SelectedValue='<%#
Bind("CategoryID") %>'>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
</div>
</form>
</body>
</html>
=======================

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.)







--------------------
| Thread-Topic: Itemtemplace and many to one dropdown example wanted
| thread-index: AcYeKy7odVEPNOMCTeO27jfTJ/6shA==
| X-WBNR-Posting-Host: 65.35.95.187
| From: "=?Utf-8?B?VGRhclRkYXI=?=" <[email protected]>
| Subject: Itemtemplace and many to one dropdown example wanted
| Date: Fri, 20 Jan 2006 17:37:04 -0800
| Lines: 14
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:32702
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Where can i find an expample of a item template that does the following
|
| example of detailsview
|
|
| name: Jack
| City: 2342
| State: 1
|
|
| I want to change the city field I assume using Itemtemplate, and have
| it link to a city table(another table) as a dropdown to display the city
| name.
|
|
 
S

Steven Cheng[MSFT]

Thanks for your response Tdar,

So your actual scenario is a bit more complex than I've expected. As you
mentioned:

====================
but how to a change one dropdown contents based on anothers current
selection.
=======================

do you mean that there is another dropdownlist control(state info) which is
used as filter of the City dropdownlist? If so, I think how to bind the
dropdownlists depend on their relationship in the control collection. Are
they put in the same parent control (a certain column in
GridView/DetailsView or ....)?

Please feel free to let me know if there's anything I misunderstood.

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.)

--------------------
| Thread-Topic: Itemtemplace and many to one dropdown example wanted
| thread-index: AcYgRZOzuS1EF2bwSpGIUCSqYZPYaQ==
| X-WBNR-Posting-Host: 24.73.223.27
| From: "=?Utf-8?B?VGRhclRkYXI=?=" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: RE: Itemtemplace and many to one dropdown example wanted
| Date: Mon, 23 Jan 2006 09:51:02 -0800
| Lines: 172
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:32750
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Hi,
| Thanks that helped, but how to a change one dropdown contents based on
| anothers current selection.
|
| as in selected state is "FL"
|
| so the cities dropdown in edit mode should only show "Citys" in "FL"
|
| I tried this but get an error:
| <asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$
| ConnectionStrings:SilverQueen_Main_SystemConnectionString1 %>"
| SelectCommand="SELECT [StateKey], [StateName], [StateCode] FROM
| [State] where StateKey = <%# Bind("StateKey") %> Order by
| [StateName]"></asp:SqlDataSource>
|
| I guess the bind statement is not valid at that time of form loading.
|
| Tdar
|
|
|
| "Steven Cheng[MSFT]" wrote:
|
| > Hi Tdar,
| >
| > Welcome.
| > Regarding on the question you mentioned, do you mean that you want to
| > display one of the column in DetailsView as a DropDownList and the
| > dropdownlist's items will be filled by data retrieved from another
database
| > table?
| >
| > If so, a simple means is add an another DataSource control which
connect to
| > the data table that contains the DropDownList's items data.... Then,
in
| > our main DataBound control(DetailsView?), we add a dropdownlist and
set
| > its datasourceID to the new datasource control and bind its
selectedValue
| > to the original databound value ......
| >
| > To make it clear, here is a simple example which display the Product
| > table's data in a DetailsView control, and it contains one column which
| > display the Category through a DropDownList....
| >
| > ==========aspx=============
| > <html xmlns="http://www.w3.org/1999/xhtml" >
| > <head runat="server">
| > <title>Untitled Page</title>
| > </head>
| > <body>
| > <form id="form1" runat="server">
| > <div>
| > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
| > ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
| > SelectCommand="SELECT [ProductID], [ProductName],
[CategoryID]
| > FROM [Products]" DeleteCommand="DELETE FROM [Products] WHERE
[ProductID] =
| > @ProductID" InsertCommand="INSERT INTO [Products] ([ProductName],
| > [CategoryID]) VALUES (@ProductName, @CategoryID)" UpdateCommand="UPDATE
| > [Products] SET [ProductName] = @ProductName, [CategoryID] = @CategoryID
| > WHERE [ProductID] = @ProductID">
| > <DeleteParameters>
| > <asp:parameter Name="ProductID" Type="Int32" />
| > </DeleteParameters>
| > <UpdateParameters>
| > <asp:parameter Name="ProductName" Type="String" />
| > <asp:parameter Name="CategoryID" Type="Int32" />
| > <asp:parameter Name="ProductID" Type="Int32" />
| > </UpdateParameters>
| > <InsertParameters>
| > <asp:parameter Name="ProductName" Type="String" />
| > <asp:parameter Name="CategoryID" Type="Int32" />
| > </InsertParameters>
| > </asp:SqlDataSource>
| > <asp:SqlDataSource ID="SqlDataSource2" runat="server"
| > ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
| > SelectCommand="SELECT [CategoryID], [CategoryName] FROM
| > [Categories]"></asp:SqlDataSource>
| > <asp:DetailsView ID="DetailsView1" runat="server"
| > AutoGenerateRows="False" DataKeyNames="ProductID"
| > DataSourceID="SqlDataSource1" Height="50px" Width="125px"
| > AllowPaging="True">
| > <Fields>
| > <asp:BoundField DataField="ProductID"
| > HeaderText="ProductID" InsertVisible="False"
| > ReadOnly="True" SortExpression="ProductID" />
| > <asp:BoundField DataField="ProductName"
| > HeaderText="ProductName" SortExpression="ProductName" />
| > <asp:TemplateField HeaderText="CategoryID"
| > SortExpression="CategoryID">
| > <EditItemTemplate>
| > <asp:DropDownList ID="DropDownList1"
| > runat="server" DataSourceID="SqlDataSource2"
| > DataTextField="CategoryName"
| > DataValueField="CategoryID" SelectedValue='<%# Bind("CategoryID") %>'>
| > </asp:DropDownList>
| > </EditItemTemplate>
| > <InsertItemTemplate>
| > <asp:TextBox ID="TextBox1" runat="server"
Text='<%#
| > Bind("CategoryID") %>'></asp:TextBox>
| > </InsertItemTemplate>
| > <ItemTemplate>
| > <asp:DropDownList ID="DropDownList2"
| > runat="server" DataSourceID="SqlDataSource2"
| > DataTextField="CategoryName"
| > DataValueField="CategoryID" Enabled="False" SelectedValue='<%#
| > Bind("CategoryID") %>'>
| > </asp:DropDownList>
| > </ItemTemplate>
| > </asp:TemplateField>
| > <asp:CommandField ShowEditButton="True" />
| > </Fields>
| > </asp:DetailsView>
| > </div>
| > </form>
| > </body>
| > </html>
| > =======================
| >
| > 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.)
| >
| >
| >
| >
| >
| >
| >
| > --------------------
| > | Thread-Topic: Itemtemplace and many to one dropdown example wanted
| > | thread-index: AcYeKy7odVEPNOMCTeO27jfTJ/6shA==
| > | X-WBNR-Posting-Host: 65.35.95.187
| > | From: "=?Utf-8?B?VGRhclRkYXI=?=" <[email protected]>
| > | Subject: Itemtemplace and many to one dropdown example wanted
| > | Date: Fri, 20 Jan 2006 17:37:04 -0800
| > | Lines: 14
| > | Message-ID: <[email protected]>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.webcontrols:32702
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
| > |
| > | Where can i find an expample of a item template that does the
following
| > |
| > | example of detailsview
| > |
| > |
| > | name: Jack
| > | City: 2342
| > | State: 1
| > |
| > |
| > | I want to change the city field I assume using Itemtemplate, and have
| > | it link to a city table(another table) as a dropdown to display the
city
| > | name.
| > |
| > |
| >
| >
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top