0% found this document useful (0 votes)
7 views

Bài Thi

The document contains code for an ASP.NET website with master pages and content pages for home, products, and login functionality. It includes C# code-behind files that connect to a SQL database and retrieve data to populate page elements.

Uploaded by

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

Bài Thi

The document contains code for an ASP.NET website with master pages and content pages for home, products, and login functionality. It includes C# code-behind files that connect to a SQL database and retrieve data to populate page elements.

Uploaded by

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

Xuly.

cs

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Data;
using System.Linq.Expressions;
using System.Xml.Serialization;
using System.EnterpriseServices;

namespace dethi
{
public class xuly
{
SqlConnection con;
//jkn
private void connect()
{
con = new SqlConnection(@"Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\hailamnam\dethi\dethi\App_Data\c
sdl.mdf;Integrated Security=True");
con.Open();
}
private void closeconnect ()
{
if (con.State == ConnectionState.Open)
con.Close();
}
public DataTable getData(String sql)
{
connect();
DataTable dt = new DataTable();
try
{
SqlDataAdapter adap = new SqlDataAdapter(sql, con);
adap.Fill(dt);
}
catch { dt = null; }
finally { closeconnect(); }
return dt;
}
}

}
Site1.aspx

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs"


Inherits="dethi.Site1" %>

<!DOCTYPE html>

<html>
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<link href="StyleSheet1.css" rel="stylesheet" />
<style>
html {
background: url("https://ben.com.vn/tin-tuc/wp-
content/uploads/2020/09/hinh-nen-anime-dep-min.jpg");
background-repeat: no-repeat;
background-size: 100%;
}

.container {
width: 100%;
height: 100%;
border-radius: 2px;
}

.left {

width: 20%;
height: auto;
float: left;
border: 10px;
}

.right {
border: 10px;
width: 20%;
height: auto;
float: right

}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<div class="left">
<h2>Danh mục loại </h2>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%#
Eval("TenDM") %>' CommandArgument='<%# Eval("MaDM") %>'
OnClick="LinkButton1_Click"></asp:LinkButton>
</ItemTemplate>
</asp:DataList>

</div>
<div class="right">
<div>
<h2>Thông tin đăng nhập </h2>
<table>
<tr>
<td>tên đăng nhập </td>
<td>
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Pass</td>
<td>
<asp:TextBox ID="TextBox2"
runat="server"></asp:TextBox>
</td>
</tr>

<tr>
<td cospan="2">
<asp:CheckBox ID="CheckBox2" runat="server" />Nhớ
pass
<asp:Button ID="Button1" runat="server" Text="Đăng
nhập" />
</td>
</tr>
</table>
</div>
</div>
<div class="content">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
<div>
</div>
</form>
</body>
</html>
Site1.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace dethi
{
public partial class Site1 : System.Web.UI.MasterPage
{
xuly kn = new xuly();
protected void Page_Load(object sender, EventArgs e)
{
if(Page.IsPostBack) return;
String q = "select * from DanhMucHoa";
try
{
this.DataList1.DataSource = kn.getData(q);
this.DataList1.DataBind();
}
catch (SqlException ex)
{
Response .Write(ex.Message);
}

protected void LinkButton1_Click(object sender, EventArgs e)


{
String madm = ((LinkButton)sender).CommandArgument;
Context.Items["mdm"] = madm;
Server.Transfer("sanpham.aspx");
}
}
}

Home.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master"


AutoEventWireup="true" CodeBehind="home.aspx.cs" Inherits="dethi.home" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
<h2> Trang chủ </h2>
</asp:Content>
Sanpham.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master"


AutoEventWireup="true" CodeBehind="sanpham.aspx.cs" Inherits="dethi.sanpham" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
<h1>sản phẩm </h1>
<asp:DataList ID="DataList1" runat="server" RepeatColumns="3">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%#
"~/img/"+Eval("HinhAnh") %>' Width="150px" />
<br />
<asp:Label ID="Label2" runat="server" Text='<%#
Eval("DonGia","{0:0}") %>'></asp:Label>
</ItemTemplate>
</asp:DataList>
</asp:Content>

Sanpham.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace dethi
{
public partial class sanpham : System.Web.UI.Page
{
xuly kn = new xuly();
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack) return;
String q;
if (Context.Items["mdm"] == null)
q = "select * from Hoa";
else
{
String madm = Context.Items["mdm"].ToString();
q = "Select * from Hoa where MaDM = '" + madm +"'";
}
try
{
this.DataList1.DataSource = kn.getData(q);
this.DataList1.DataBind();
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}

}
}
}

You might also like