Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Itemtemplace and many to one dropdown example wanted

Reply
Thread Tools

Itemtemplace and many to one dropdown example wanted

 
 
TdarTdar
Guest
Posts: n/a
 
      01-21-2006
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.

 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      01-23-2006
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>
<asparameter Name="ProductID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="ProductName" Type="String" />
<asparameter Name="CategoryID" Type="Int32" />
<asparameter Name="ProductID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="ProductName" Type="String" />
<asparameter Name="CategoryID" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName] FROM
[Categories]"></asp:SqlDataSource>
<aspetailsView 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;<aspropDownList ID="DropDownList1"
runat="server" DataSourceID="SqlDataSource2"
DataTextField="CategoryName"
DataValueField="CategoryID" SelectedValue='<%# Bind("CategoryID") %>'>
</aspropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("CategoryID") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
&nbsp;<aspropDownList ID="DropDownList2"
runat="server" DataSourceID="SqlDataSource2"
DataTextField="CategoryName"
DataValueField="CategoryID" Enabled="False" SelectedValue='<%#
Bind("CategoryID") %>'>
</aspropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
</aspetailsView>
</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=?=" <>
| Subject: Itemtemplace and many to one dropdown example wanted
| Date: Fri, 20 Jan 2006 17:37:04 -0800
| Lines: 14
| Message-ID: <DB561767-E612-4C0E-A000->
| 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.webcontro ls
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontro ls:32702
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontro ls
|
| 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.
|
|

 
Reply With Quote
 
 
 
 
TdarTdar
Guest
Posts: n/a
 
      01-23-2006
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_SystemConnectio nString1 %>"
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>
> <asparameter Name="ProductID" Type="Int32" />
> </DeleteParameters>
> <UpdateParameters>
> <asparameter Name="ProductName" Type="String" />
> <asparameter Name="CategoryID" Type="Int32" />
> <asparameter Name="ProductID" Type="Int32" />
> </UpdateParameters>
> <InsertParameters>
> <asparameter Name="ProductName" Type="String" />
> <asparameter Name="CategoryID" Type="Int32" />
> </InsertParameters>
> </asp:SqlDataSource>
> <asp:SqlDataSource ID="SqlDataSource2" runat="server"
> ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
> SelectCommand="SELECT [CategoryID], [CategoryName] FROM
> [Categories]"></asp:SqlDataSource>
> <aspetailsView 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>
> <aspropDownList ID="DropDownList1"
> runat="server" DataSourceID="SqlDataSource2"
> DataTextField="CategoryName"
> DataValueField="CategoryID" SelectedValue='<%# Bind("CategoryID") %>'>
> </aspropDownList>
> </EditItemTemplate>
> <InsertItemTemplate>
> <asp:TextBox ID="TextBox1" runat="server" Text='<%#
> Bind("CategoryID") %>'></asp:TextBox>
> </InsertItemTemplate>
> <ItemTemplate>
> <aspropDownList ID="DropDownList2"
> runat="server" DataSourceID="SqlDataSource2"
> DataTextField="CategoryName"
> DataValueField="CategoryID" Enabled="False" SelectedValue='<%#
> Bind("CategoryID") %>'>
> </aspropDownList>
> </ItemTemplate>
> </asp:TemplateField>
> <asp:CommandField ShowEditButton="True" />
> </Fields>
> </aspetailsView>
> </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=?=" <>
> | Subject: Itemtemplace and many to one dropdown example wanted
> | Date: Fri, 20 Jan 2006 17:37:04 -0800
> | Lines: 14
> | Message-ID: <DB561767-E612-4C0E-A000->
> | 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.webcontro ls
> | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
> | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
> | Xref: TK2MSFTNGXA02.phx.gbl
> microsoft.public.dotnet.framework.aspnet.webcontro ls:32702
> | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontro ls
> |
> | 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.
> |
> |
>
>

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      01-24-2006
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=?=" <>
| References: <DB561767-E612-4C0E-A000->
<d0xSqF$>
| Subject: RE: Itemtemplace and many to one dropdown example wanted
| Date: Mon, 23 Jan 2006 09:51:02 -0800
| Lines: 172
| Message-ID: <77EA8A99-ADF2-41D9-BEC3->
| 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.webcontro ls
| 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.webcontro ls:32750
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontro ls
|
| 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_SystemConnectio nString1 %>"
| 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>
| > <asparameter Name="ProductID" Type="Int32" />
| > </DeleteParameters>
| > <UpdateParameters>
| > <asparameter Name="ProductName" Type="String" />
| > <asparameter Name="CategoryID" Type="Int32" />
| > <asparameter Name="ProductID" Type="Int32" />
| > </UpdateParameters>
| > <InsertParameters>
| > <asparameter Name="ProductName" Type="String" />
| > <asparameter Name="CategoryID" Type="Int32" />
| > </InsertParameters>
| > </asp:SqlDataSource>
| > <asp:SqlDataSource ID="SqlDataSource2" runat="server"
| > ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
| > SelectCommand="SELECT [CategoryID], [CategoryName] FROM
| > [Categories]"></asp:SqlDataSource>
| > <aspetailsView 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>
| > <aspropDownList ID="DropDownList1"
| > runat="server" DataSourceID="SqlDataSource2"
| > DataTextField="CategoryName"
| > DataValueField="CategoryID" SelectedValue='<%# Bind("CategoryID") %>'>
| > </aspropDownList>
| > </EditItemTemplate>
| > <InsertItemTemplate>
| > <asp:TextBox ID="TextBox1" runat="server"
Text='<%#
| > Bind("CategoryID") %>'></asp:TextBox>
| > </InsertItemTemplate>
| > <ItemTemplate>
| > <aspropDownList ID="DropDownList2"
| > runat="server" DataSourceID="SqlDataSource2"
| > DataTextField="CategoryName"
| > DataValueField="CategoryID" Enabled="False" SelectedValue='<%#
| > Bind("CategoryID") %>'>
| > </aspropDownList>
| > </ItemTemplate>
| > </asp:TemplateField>
| > <asp:CommandField ShowEditButton="True" />
| > </Fields>
| > </aspetailsView>
| > </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=?=" <>
| > | Subject: Itemtemplace and many to one dropdown example wanted
| > | Date: Fri, 20 Jan 2006 17:37:04 -0800
| > | Lines: 14
| > | Message-ID: <DB561767-E612-4C0E-A000->
| > | 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.webcontro ls
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.webcontro ls:32702
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontro ls
| > |
| > | 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.
| > |
| > |
| >
| >
|

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
many aspnet applications in one site? many Gloabal.asax files ok? dee ASP .Net 2 08-15-2005 03:07 AM
Embedding: many interpreters OR one interpreter with many thread states ? adsheehan@eircom.net Python 3 06-10-2005 03:18 AM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 1 07-16-2004 01:12 PM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 0 07-16-2004 10:00 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57