Bài Thi
Bài Thi
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
<!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);
}
Home.aspx
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);
}
}
}
}