0% found this document useful (0 votes)
8 views3 pages

%@ Page Language C# AutoEventWireup

The document is an ASP.NET web page that allows an admin to manage categories and products in a bookstore. It includes dropdowns for selecting categories, grid views for displaying products and categories, and forms for adding new categories. The page utilizes SQL data sources for data retrieval and manipulation, supporting operations like insert, update, and delete.

Uploaded by

kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

%@ Page Language C# AutoEventWireup

The document is an ASP.NET web page that allows an admin to manage categories and products in a bookstore. It includes dropdowns for selecting categories, grid views for displaying products and categories, and forms for adding new categories. The page utilizes SQL data sources for data retrieval and manipulation, supporting operations like insert, update, and delete.

Uploaded by

kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Admin.aspx.

cs"
Inherits="Ch06Cart.Admin" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>Choose Categories:</h2>
<asp:DropDownList ID="ddlCategories" runat="server" AutoPostBack="true"
DataSourceID="SqlDataSourceCategory" DataTextField="Name"
DataValueField="CategoryID" CssClass="form-control">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceCategory" runat="server"
ConnectionString='<%$ ConnectionStrings:NiveshBookStoreDBConnection %>'
SelectCommand="SELECT CategoryID, ShortName+LongName as Name FROM [Categories]
"></asp:SqlDataSource>
</div>
<div>
<h2>Products</h2>
<asp:GridView ID="GridViewProducts" runat="server"
AutoGenerateColumns="False" DataSourceID="SqlDataSourceProducts">
<Columns>
<asp:BoundField DataField="ProductName" HeaderText="Product
Name" />
<asp:BoundField DataField="ProductDescription"
HeaderText="Product Description" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceProducts" runat="server"
ConnectionString='<%$ ConnectionStrings:NiveshBookStoreDBConnection %>'
SelectCommand="SELECT [Name] AS ProductName, [ShortDescription] AS
ProductDescription FROM [Products] WHERE [CategoryID] = @CategoryID">
<SelectParameters>
<asp:ControlParameter ControlID="ddlCategories"
Name="CategoryID" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
</div>
<div>
<h2>Categories</h2>
<asp:GridView ID="GridViewCategories" runat="server"
AutoGenerateColumns="False" DataKeyNames="CategoryID"
DataSourceID="SqlDataSourceCategories">
<Columns>
<asp:BoundField DataField="CategoryID" HeaderText="Category ID"
ReadOnly="True" />
<asp:BoundField DataField="ShortName" HeaderText="Short
Name" />
<asp:BoundField DataField="LongName" HeaderText="Long Name" />
<asp:CommandField ShowEditButton="True" ShowDeleteButton="True"
/>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceCategories" runat="server"
ConnectionString='<%$ ConnectionStrings:NiveshBookStoreDBConnection %>'
SelectCommand="SELECT * FROM Categories" UpdateCommand="UPDATE Categories SET
ShortName = @ShortName, LongName = @LongName WHERE CategoryID = @CategoryID"
DeleteCommand="DELETE FROM Categories WHERE CategoryID = @CategoryID">
<UpdateParameters>
<asp:Parameter Name="ShortName" Type="String" />
<asp:Parameter Name="LongName" Type="String" />
<asp:Parameter Name="CategoryID" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
<div>
<h2>Add New Category</h2>
<asp:TextBox ID="txtCategoryID" name="txtCategoryID" runat="server"
CssClass="form-control" placeholder="CategoryName"></asp:TextBox>
<asp:TextBox ID="txtShortName" name="txtShortName" runat="server"
CssClass="form-control" placeholder="Short Name"></asp:TextBox>
<asp:TextBox ID="txtLongName" name="txtLongName" runat="server"
CssClass="form-control" placeholder="Long Name"></asp:TextBox>
<asp:Button ID="btnAddCategory" runat="server" Text="Add Category"
OnClick="btnAddCategory_Click" CssClass="btn btn-primary" />
</div>
<div class="row">
<h2>Products</h2>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateInsertButton="True" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" DataKeyNames="ProductID" AllowSorting="True"
AllowPaging="True" EnableViewState="False">
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="Product ID"
ReadOnly="True" />
<asp:BoundField DataField="Name" HeaderText="Product Name" />
<asp:BoundField DataField="ShortDescription" HeaderText="Short
Description" />
<asp:BoundField DataField="LongDescription" HeaderText="Long
Description" />
<asp:BoundField DataField="CategoryID" HeaderText="Category ID"
/>
<asp:BoundField DataField="ImageFile" HeaderText="Image
File" />
<asp:BoundField DataField="UnitPrice" HeaderText="Unit
Price" />
<asp:BoundField DataField="OnHand" HeaderText="On Hand" />
<asp:CommandField ShowEditButton="True" ShowDeleteButton="True"
ShowInsertButton="True" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString='<%$ ConnectionStrings:NiveshBookStoreDBConnection %>'
SelectCommand="SELECT [ProductID], [Name], [ShortDescription],
[LongDescription], [CategoryID], [ImageFile], [UnitPrice], [OnHand] FROM
[Products]"
UpdateCommand="UPDATE [Products] SET [Name] = @Name,
[ShortDescription] = @ShortDescription, [LongDescription] = @LongDescription,
[CategoryID] = @CategoryID, [ImageFile] = @ImageFile, [UnitPrice] = @UnitPrice,
[OnHand] = @OnHand WHERE [ProductID] = @ProductID"
DeleteCommand="DELETE FROM [Products] WHERE [ProductID] =
@ProductID"
InsertCommand=" INSERT INTO [Products] ([ProductID], [Name],
[ShortDescription], [LongDescription], [CategoryID], [ImageFile], [UnitPrice],
[OnHand]) VALUES (@ProductID, @Name, @ShortDescription, @LongDescription,
@CategoryID, @ImageFile, @UnitPrice, @OnHand)">

<InsertParameters>
<asp:Parameter Name="ProductID" Type="String" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="ShortDescription" Type="String" />
<asp:Parameter Name="LongDescription" Type="String" />
<asp:Parameter Name="CategoryID" Type="String" />
<asp:Parameter Name="ImageFile" Type="String" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
<asp:Parameter Name="OnHand" Type="Int32" />
</InsertParameters>

<DeleteParameters>
<asp:Parameter Name="ProductID" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="ShortDescription" Type="String" />
<asp:Parameter Name="LongDescription" Type="String" />
<asp:Parameter Name="CategoryID" Type="String" />
<asp:Parameter Name="ImageFile" Type="String" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
<asp:Parameter Name="OnHand" Type="Int32" />
<asp:Parameter Name="ProductID" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>

You might also like