zoukankan
html css js c++ java
GridView之学习一
Default.aspx
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
Default.aspx.cs
"
Inherits
=
"
_Default
"
%>
<!
DOCTYPE html PUBLIC
"
-//W3C//DTD XHTML 1.0 Transitional//EN
"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
"
>
<
html xmlns
=
"
http://www.w3.org/1999/xhtml
"
>
<
head runat
=
"
server
"
>
<
title
>
无标题页
</
title
>
</
head
>
<
body
>
<
form id
=
"
form1
"
runat
=
"
server
"
>
<
div
>
<
asp:GridView ID
=
"
GridView1
"
runat
=
"
server
"
AllowPaging
=
"
True
"
AutoGenerateColumns
=
"
False
"
BackColor
=
"
White
"
BorderColor
=
"
#CCCCCC
"
BorderStyle
=
"
None
"
BorderWidth
=
"
1px
"
CellPadding
=
"
3
"
OnPageIndexChanging
=
"
GridView1_PageIndexChanging
"
PageSize
=
"
5
"
>
<
PagerSettings FirstPageImageUrl
=
"
~/Images/First.gif
"
FirstPageText
=
"
|&lt;
"
LastPageImageUrl
=
"
~/Images/Last.gif
"
LastPageText
=
"
&gt;|
"
Mode
=
"
NumericFirstLast
"
NextPageImageUrl
=
"
~/Images/Next.gif
"
PageButtonCount
=
"
5
"
PreviousPageImageUrl
=
"
~/Images/Previous.gif
"
/>
<
FooterStyle BackColor
=
"
White
"
ForeColor
=
"
#000066
"
/>
<
Columns
>
<
asp:BoundField DataField
=
"
ClientName
"
HeaderText
=
"
姓名
"
SortExpression
=
"
Name
"
/>
<
asp:BoundField DataField
=
"
AddressStr
"
HeaderText
=
"
地址
"
SortExpression
=
"
Address
"
/>
<
asp:BoundField DataField
=
"
PostCode
"
HeaderText
=
"
邮编
"
SortExpression
=
"
PostCode
"
/>
</
Columns
>
<
RowStyle ForeColor
=
"
#000066
"
/>
<
SelectedRowStyle BackColor
=
"
#669999
"
Font
-
Bold
=
"
True
"
ForeColor
=
"
White
"
/>
<
PagerStyle BackColor
=
"
#FFC080
"
BorderColor
=
"
Blue
"
Font
-
Bold
=
"
True
"
ForeColor
=
"
#000066
"
HorizontalAlign
=
"
Left
"
/>
<
HeaderStyle BackColor
=
"
#006699
"
Font
-
Bold
=
"
True
"
ForeColor
=
"
White
"
/>
</
asp:GridView
>
</
div
>
</
form
>
</
body
>
</
html
>
ClientInfo.cs
using
System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
/**/
///
<summary>
///
ClientInfo 的摘要说明
///
</summary>
public
class
ClientInfo
{
private
int
clientID;
//
客户编号
public
int
ClientID
{
get
{
return
clientID; }
set
{ clientID
=
value; }
}
private
string
clientName;
//
客户姓名
public
string
ClientName
{
get
{
return
clientName; }
set
{ clientName
=
value; }
}
private
string
addressStr;
//
客户地址
public
string
AddressStr
{
get
{
return
addressStr; }
set
{ addressStr
=
value; }
}
private
string
postCode;
//
客户邮编
public
string
PostCode
{
get
{
return
postCode; }
set
{ postCode
=
value; }
}
private
string
telephone;
//
客户电话
public
string
Telephone
{
get
{
return
telephone; }
set
{ telephone
=
value; }
}
private
string
email;
//
客户邮件
public
string
Email
{
get
{
return
email; }
set
{ email
=
value; }
}
}
ClientInfoAccessObj.cs
using
System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Collections.Generic;
using
System.Data.SqlClient;
/**/
///
<summary>
///
ClientInfoAccessObj 的摘要说明
///
</summary>
public
class
ClientInfoAccessObj
{
//
连接字符串
private
readonly
string
connString
=
"
server=.\\sqlexpress;database=Clients;uid=sa;pwd=123456;
"
;
//
获得所有的客户信息
public
List
<
ClientInfo
>
GetAllClients()
{
List
<
ClientInfo
>
clients
=
new
List
<
ClientInfo
>
();
using
(SqlConnection conn
=
new
SqlConnection(connString))
{
string
sql
=
"
select * from orderClient
"
;
using
(SqlCommand comm
=
new
SqlCommand(sql,conn))
{
conn.Open();
using
(SqlDataReader sdr
=
comm.ExecuteReader())
{
while
(sdr.Read())
{
ClientInfo ci
=
new
ClientInfo();
ci.ClientID
=
int
.Parse(sdr[
"
ClientID
"
].ToString());
ci.ClientName
=
sdr[
"
ClientName
"
].ToString();
ci.AddressStr
=
sdr[
"
AddressStr
"
].ToString();
ci.PostCode
=
sdr[
"
PostCode
"
].ToString();
ci.Telephone
=
sdr[
"
Telephone
"
].ToString();
ci.Email
=
sdr[
"
Email
"
].ToString();
clients.Add(ci);
}
return
clients;
}
}
}
}
}
Default.aspx.cs
using
System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
public
partial
class
_Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
IsPostBack)
{
ClientInfoAccessObj obj
=
new
ClientInfoAccessObj();
GridView1.DataSource
=
obj.GetAllClients();
GridView1.DataBind();
}
}
protected
void
GridView1_PageIndexChanging(
object
sender, GridViewPageEventArgs e)
{
ClientInfoAccessObj obj
=
new
ClientInfoAccessObj();
GridView1.DataSource
=
obj.GetAllClients();
GridView1.PageIndex
=
e.NewPageIndex;
//
将点击的新页下标赋给GridView
GridView1.DataBind();
}
}
查看全文
相关阅读:
2019-2020-2 网络对抗技术 20175217 Exp6 MSF基础应用
2020_1课程设计—基于BC的证书格式转换工具的设计与实现—第二周进展
2019-2020-2 网络对抗技术 20175217 Exp5 信息搜集与漏洞扫描
2019-2020-2 网络对抗技术 20175217 Exp4 恶意代码分析
2019-2020-2 网络对抗技术 20175205 Exp 9 Web安全基础
2019-2020-2 网络对抗技术 20175205 Exp8 Web基础
2019-2020-2 网络对抗技术 20175205 Exp7 网络欺诈防范
2020_1课程设计—基于BC的证书格式转换工具的设计与实现—个人报告
2020_1课程设计—基于BC的证书格式转换工具的设计与实现—Week3
2019-2020-2 网络对抗技术 20175205 Exp6 MSF基础应用
原文地址:https://www.cnblogs.com/mdy41034264/p/1351427.html
最新文章
20192428 网络空间安全专业导论
20192428 获奖感想与网络空间安全专业导论总结
2019-2020-1学期 20192428《THE LINUX COMMAND LINE 》读数笔记一
2019-2020-1学期 20192428《网络空间安全专业导论》第十二周学习总结
2019-2020-1学期 20192428 《网络空间安全专业导论》第十一周学习总结
2019-2020-1学期 20192428 《网络空间安全专业导论》第十周小组讨论
python/flask 命令执行tips
ssrf与redis安全
刷题记录:[网鼎杯 2020 玄武组]SSRFMe
2019-2020-2 网络对抗技术 20175211 免考项目 zzcms201910审计
热门文章
刷题记录:[网鼎杯 2020 朱雀组]Think Java
敏感文件读取
刷题记录:[GKCTF2020]cve版签到
2019-2020-2 网络对抗技术 20175211 Exp9 Web安全基础
2019-2020-2 网络对抗技术 20175217 Exp9 Web安全基础
2019-2020-2 网络对抗技术 20175217 Exp 8 Web基础
2019-2020-2 网络对抗技术 20175217 Exp7 网络欺诈防范
2020_1课程设计—基于BC的证书格式转换工具的设计与实现—小组博客
2020_1课程设计—基于BC的证书格式转换工具的设计与实现—个人报告
2020_1课程设计—基于BC的证书格式转换工具的设计与实现—第三周进展
Copyright © 2011-2022 走看看