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();
}
}
查看全文
相关阅读:
奔驰4-MATIC和奥迪quattro的区别和共同点是什么(杂记)
ibatis.net:QueryForObject(转)
iBatis入门(转)
javax.servlet.ServletException: java.lang.NullPointerException 空指针异常
报错:Action[/statisticsManage] does not contain specified method (check logs)
eclipse下,64位tomcat报错(转)
Resource '/servers' does not exist 问题的解决(转)
Ext.data.SimpleStore的使用方法
combo的displayField和valueField属性
Exception occurred during processing request: null java.lang.NullPointerException
原文地址:https://www.cnblogs.com/mdy41034264/p/1351427.html
最新文章
python re 模块 正则表达式
python configparser 模块
python logging 模块
python hashlib 模块
python sys 模块
python os 模块
在 WPF 中的线程
SQL 索引查找
WPF (VisualChildren)可视化子元素详解
MVC FileResult
热门文章
sql 模版
ListView 视图(View)
WPF DataGrid常用属性记录
asp.net MVC 4.0 View回顾——布局页与分部页
WPF 动态加载主题由zip
wpf ComboBox的SelectionBoxItem相关依赖属性
js瀑布流布局
js懒加载
Ajax、json、jsonp
利用Extjs导出excel文件(转)
Copyright © 2011-2022 走看看