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