Itemtemplace and many to one dropdown example wanted

Discussion in 'ASP .Net Web Controls' started by TdarTdar, Jan 21, 2006.

  1. TdarTdar

    TdarTdar Guest

    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.
     
    TdarTdar, Jan 21, 2006
    #1
    1. Advertising

  2. 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=?=" <>
    | Subject: Itemtemplace and many to one dropdown example wanted
    | Date: Fri, 20 Jan 2006 17:37:04 -0800
    | Lines: 14
    | Message-ID: <>
    | 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.
    |
    |
     
    Steven Cheng[MSFT], Jan 23, 2006
    #2
    1. Advertising

  3. TdarTdar

    TdarTdar Guest

    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=?=" <>
    > | Subject: Itemtemplace and many to one dropdown example wanted
    > | Date: Fri, 20 Jan 2006 17:37:04 -0800
    > | Lines: 14
    > | Message-ID: <>
    > | 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.
    > |
    > |
    >
    >
     
    TdarTdar, Jan 23, 2006
    #3
  4. 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: <>
    <d0xSqF$>
    | Subject: RE: Itemtemplace and many to one dropdown example wanted
    | Date: Mon, 23 Jan 2006 09:51:02 -0800
    | Lines: 172
    | Message-ID: <>
    | 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=?=" <>
    | > | Subject: Itemtemplace and many to one dropdown example wanted
    | > | Date: Fri, 20 Jan 2006 17:37:04 -0800
    | > | Lines: 14
    | > | Message-ID: <>
    | > | 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.
    | > |
    | > |
    | >
    | >
    |
     
    Steven Cheng[MSFT], Jan 24, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harvey
    Replies:
    0
    Views:
    717
    Harvey
    Jul 16, 2004
  2. Harvey
    Replies:
    1
    Views:
    853
    Daniel
    Jul 16, 2004
  3. dee
    Replies:
    2
    Views:
    399
  4. Replies:
    3
    Views:
    319
  5. jason
    Replies:
    6
    Views:
    169
Loading...

Share This Page