Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 4 and Visual Studio 2010 > .NET 4 and Visual Studio 2010 General Discussions
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
.NET 4 and Visual Studio 2010 General Discussions For discussing anything about .NET 4, WPF, WCF, the rest of the .NET 4 Framework, and Visual Studio 2010 that isn't about a specific Wrox book. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET 4 and Visual Studio 2010 General Discussions section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 10th, 2011, 05:23 PM
Authorized User
Points: 52, Level: 1
Points: 52, Level: 1 Points: 52, Level: 1 Points: 52, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2011
Location: Ankara Turkey
Posts: 13
Thanks: 7
Thanked 0 Times in 0 Posts
Default dropdownlist field connected to table data not working

Hi,

I am new to asp.net

I have two tables
Quote:
table name: Product
Fields list:
ProductId (primary key field) - int
ProductName - nvarchar(150)
Category - nvarchar(50)
Price - int
SystemInputDate - datetime
Quote:
table name: Category
Fields list:
Category (primary key field) - nvarchar(50)
Id - int
SystemInputDate - datetime
at the database diagram: category from category table (one) is connected to category from product table (to many): one to many connection

my objective was:
I wanted to make a dropdownlist inside a detailsview of product.aspx page where user inputs data to product table. User when inputing for the category field he/she will have to select only from the dropdown list where it gets its feed from the category table. the data selected and other input details will be inputed in a record of the table product.

I tried to find a solution :
I used the following post:

inserting Dropdownlist in Data Grid.

I have the following errors:
template column: is not known element
ItemTemplate is not supported
dropdownlist is not known element


here is the place where i have problem:

Code:
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
        DataKeyNames="ProductId" DataSourceID="SqlDataSource1" Height="50px" 
        Width="125px">
        <Fields>
            <asp:BoundField DataField="ProductId" HeaderText="ProductId" 
                InsertVisible="False" ReadOnly="True" SortExpression="ProductId" />
            <asp:BoundField DataField="ProductName" HeaderText="ProductName" 
                SortExpression="ProductName" />
            <asp:BoundField DataField="Category" HeaderText="Category" 
                SortExpression="Category" />
            <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
            <asp:BoundField DataField="SystemInputDate" HeaderText="SystemInputDate" 
                SortExpression="SystemInputDate" />
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                ShowInsertButton="True" />
            <asp:TemplateField>
            
            <asp:TemplateColumn HeaderText="Address 2">
            <ItemTemplate>
            <asp:dropdownlist 
            runat=server
            id=categoryddl
            DataTextField="Category"
            DataValueField="Id"
            DataSource='<%#Category()%>'>
            </dropdownlist>
            </ItemTemplate>
            </asp:TemplateColumn>
            
            </asp:TemplateField>
        </Fields>
    </asp:DetailsView>
here is my entire code:

Code:
<%@ Page Title="Product" Language="VB" MasterPageFile="~/MasterPages/ProdSupervisor.master" AutoEventWireup="false" CodeFile="Product.aspx.vb" Inherits="SPV_Product_Product" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="ProductId" DataSourceID="SqlDataSource4" AllowSorting="True">
        <Columns>
            <asp:BoundField DataField="ProductId" HeaderText="ProductId" ReadOnly="True" 
                SortExpression="ProductId" InsertVisible="False" />
            <asp:BoundField DataField="ProductName" HeaderText="ProductName" 
                SortExpression="ProductName" />
            <asp:BoundField DataField="Price" 
                HeaderText="Price" SortExpression="Price" />
            <asp:BoundField DataField="Category" HeaderText="Category" 
                SortExpression="Category" />

            <asp:BoundField DataField="SystemInputDate" HeaderText="SystemInputDate" 
                SortExpression="SystemInputDate" />
        </Columns>
    </asp:GridView>
    <a href="AddEditProduct.aspx">Insert New product</a><asp:SqlDataSource 
        ID="SqlDataSource3" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ProductsConnectionString1 %>" 
        DeleteCommand="DELETE FROM [Category] WHERE [Category] = @Category" 
        InsertCommand="INSERT INTO [Category] ([Category], [SystemInputDate]) VALUES (@Category, @SystemInputDate)" 
        SelectCommand="SELECT [Category], [Id], [SystemInputDate] FROM [Category] WHERE ([Id] = @Id)" 
        UpdateCommand="UPDATE [Category] SET [Id] = @Id, [SystemInputDate] = @SystemInputDate WHERE [Category] = @Category">
        <DeleteParameters>
            <asp:Parameter Name="Category" Type="String" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="Category" Type="String" />
            <asp:Parameter DbType="Date" Name="SystemInputDate" />
        </InsertParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="DropDownList1" Name="Id" 
                PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="Id" Type="Int32" />
            <asp:Parameter DbType="Date" Name="SystemInputDate" />
            <asp:Parameter Name="Category" Type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
        DataKeyNames="ProductId" DataSourceID="SqlDataSource1" Height="50px" 
        Width="125px">
        <Fields>
            <asp:BoundField DataField="ProductId" HeaderText="ProductId" 
                InsertVisible="False" ReadOnly="True" SortExpression="ProductId" />
            <asp:BoundField DataField="ProductName" HeaderText="ProductName" 
                SortExpression="ProductName" />
            <asp:BoundField DataField="Category" HeaderText="Category" 
                SortExpression="Category" />
            <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
            <asp:BoundField DataField="SystemInputDate" HeaderText="SystemInputDate" 
                SortExpression="SystemInputDate" />
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                ShowInsertButton="True" />
            <asp:TemplateField>
            
            <asp:TemplateColumn HeaderText="Address 2">
            <ItemTemplate>
            <asp:dropdownlist 
            runat=server
            id=categoryddl
            DataTextField="Category"
            DataValueField="Id"
            DataSource='<%#Category()%>'>
            </dropdownlist>
            </ItemTemplate>
            </asp:TemplateColumn>
            
            </asp:TemplateField>
        </Fields>
    </asp:DetailsView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ProductsConnectionString1 %>" 
        DeleteCommand="DELETE FROM [Product] WHERE [ProductId] = @ProductId" 
        InsertCommand="INSERT INTO [Product] ([ProductName], [Category], [Price], [SystemInputDate]) VALUES (@ProductName, @Category, @Price, @SystemInputDate)" 
        ProviderName="<%$ ConnectionStrings:ProductsConnectionString1.ProviderName %>" 
        SelectCommand="SELECT [ProductId], [ProductName], [Category], [Price], [SystemInputDate] FROM [Product]" 
        UpdateCommand="UPDATE [Product] SET [ProductName] = @ProductName, [Category] = @Category, [Price] = @Price, [SystemInputDate] = @SystemInputDate WHERE [ProductId] = @ProductId">
        <DeleteParameters>
            <asp:Parameter Name="ProductId" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="ProductName" Type="String" />
            <asp:Parameter Name="Category" Type="String" />
            <asp:Parameter Name="Price" Type="Int32" />
            <asp:Parameter DbType="Date" Name="SystemInputDate" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="ProductName" Type="String" />
            <asp:Parameter Name="Category" Type="String" />
            <asp:Parameter Name="Price" Type="Int32" />
            <asp:Parameter DbType="Date" Name="SystemInputDate" />
            <asp:Parameter Name="ProductId" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>



    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" DataSourceID="SqlDataSource4" DataTextField="Category" DataValueField="Id" AppendDataBoundItems="true" >
        <asp:ListItem>Make a selection</asp:ListItem>
    </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSource4" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ProductsConnectionString1 %>" 
        
        SelectCommand="SELECT [ProductId], [ProductName], [Price], [Category], [SystemInputDate] FROM [Product] ORDER BY [Category], [ProductName]" 
        DeleteCommand="DELETE FROM [Product] WHERE [ProductId] = @ProductId" 
        InsertCommand="INSERT INTO [Product] ([ProductName], [Price], [Category], [SystemInputDate]) VALUES (@ProductName, @Price, @Category, @SystemInputDate)" 
        UpdateCommand="UPDATE [Product] SET [ProductName] = @ProductName, [Price] = @Price, [Category] = @Category, [SystemInputDate] = @SystemInputDate WHERE [ProductId] = @ProductId">
        <DeleteParameters>
            <asp:Parameter Name="ProductId" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="ProductName" Type="String" />
            <asp:Parameter Name="Price" Type="Int32" />
            <asp:Parameter Name="Category" Type="String" />
            <asp:Parameter DbType="Date" Name="SystemInputDate" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="ProductName" Type="String" />
            <asp:Parameter Name="Price" Type="Int32" />
            <asp:Parameter Name="Category" Type="String" />
            <asp:Parameter DbType="Date" Name="SystemInputDate" />
            <asp:Parameter Name="ProductId" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    </asp:Content>
--------------
Please help thank you

Last edited by oruckenan; October 10th, 2011 at 03:47 PM.. Reason: wrap code inside code tag
  #2 (permalink)  
Old August 12th, 2011, 09:28 AM
Authorized User
Points: 52, Level: 1
Points: 52, Level: 1 Points: 52, Level: 1 Points: 52, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2011
Location: Ankara Turkey
Posts: 13
Thanks: 7
Thanked 0 Times in 0 Posts
Default

isn`t there anyone here to answer this question? I even didn`t get one answer since many days.
Please anybody help!!
  #3 (permalink)  
Old August 12th, 2011, 05:46 PM
Authorized User
Points: 52, Level: 1
Points: 52, Level: 1 Points: 52, Level: 1 Points: 52, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2011
Location: Ankara Turkey
Posts: 13
Thanks: 7
Thanked 0 Times in 0 Posts
Default

Ok I got the answer, I think I messed up with the code at the top.
I followed again the book of beginning asp.net of Imar Spanjaars and recreated the form.
Then I found the answer for the dropdownlist at the hyperlink:
DropDown List and user input

Basically it says the answer is at page 466 and 467 of the page: and now all is well.
To moderator of the forum: this question is resolved so you can close it.

Thank you
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
2 field Values within DropDownList.DataValueField rit01 ASP.NET 2.0 Basics 4 May 11th, 2016 03:22 AM
2 table views in DropDownList control yukijocelyn ASP.NET 2.0 Basics 31 October 1st, 2007 10:16 PM
Retrieve different data from same table /field W052107 Visual Studio 2005 7 August 6th, 2007 10:40 AM
Help with DropDownList on String Value Field reidcor BOOK: ASP.NET Website Programming Problem-Design-Solution 1 May 31st, 2005 08:44 AM
Empty table for dropdownlist. macupryk BOOK: ASP.NET Website Programming Problem-Design-Solution 2 August 16th, 2004 06:33 AM



All times are GMT -4. The time now is 09:53 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.