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();
}
}
查看全文
相关阅读:
201521123099 《Java程序设计》第6周学习总结
201521123099《java程序设计》第五周学习总结
201521123099 《Java程序设计》第3周学习总结
201521123099 《Java程序设计》第9周学习总结
201521123099 《Java程序设计》第4周学习总结
陈敏第一周Java课程总结
maven常见配置
使用swagger管理接口
Reportng配置报告地址
Testng基本问题
原文地址:https://www.cnblogs.com/mdy41034264/p/1351427.html
最新文章
怎样合理使用键盘以及键盘的保养方法
手机QQ如何节省流量
如何取消IP地址的绑定
如何给Excel电子表格添加水印
Win8全局搜索如何设置
如何保养存储卡,延长存储卡的寿命?
防止密码被盗的三种方法
/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found
网站修改标题之后会怎么样
诚聘图像可视化软件开发工程师
热门文章
房租支付平台“租房宝”获千万投资
亚马逊发力,电商的竞争由价格转向了物流
诚招C#软件开发工程师
如何提升被降权网站的权重恢复网站主页排名
深度seo优化的悲剧
未来团购网的发展方向:垂直化细分
做网站需要持之以恒
分享:从百度K站到恢复收录的10点经验教训
201521123099 《Java程序设计》第2周学习总结
201521123099 《Java程序设计》第八周学习总结
Copyright © 2011-2022 走看看