All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
javascript,动态添加表格行_JavaScript技术_编程技术
ASP.NET技巧:获取数据行数据信息_.net资料_编程技术
新瓶旧酒ASP.NET,AJAX(3),-,客户端脚本编程(调试和跟踪)_[Asp.Net教程]
用PHP实现Ftp用户的在线管理_[PHP教程]
利用UrlRewrite,asp.net动态生成htm页面(补充说明2)_[Asp.Net教程]
ASP.NET技巧:DataGrid传统分页方式_.net资料_编程技术
Visual C++ 6.0教程:#include文件包含指令
ASP.NET技巧:获取本机上配置好的Oracle服务名_.net资料_编程技术
,2.0,中快速实现单点登陆_[Asp.Net教程]
C#中FlowLayoutPanel控件用法以及实例
Reading number is top 10 pictures
运动的范冰冰1
Summer is most suitable for young people to travel in China10
日本小萝莉1
随便发几张图
Summer is most suitable for young people to travel in China6
The real super beauty2
俄罗斯台球天后惊艳魅惑2
Beautiful Japanese beauty(漂亮的日本美女)3
The money of more than 100 countries and regions15
In the world the most mysterious 21 place landscape2
Download software ranking
Unix video tutorial5
超级战舰
Tram sex maniac 2 (H) rar bag18
The Bermuda triangle1
Visual C++界面编程技术
Macromedia Dreamweaver 8
Sora aoi 120 minutes
网络管理员第三版
Tram sex maniac 2 (H) rar bag7
Unix video tutorial19
qq published in(发表于) 2014/7/9 1:36:21 Edit(编辑)
asp.net2.0中GridView控件应用实例

asp.net2.0中GridView控件应用实例

asp.net2.0中GridView控件应用实例

GridView控件应用实例

在开发某些管理网站或系统时,常常需要通过选中某行前面的CheckBox复选框对该行信息进行操作。本实例通过在GridView控件中添加一个CheckBox模板列来删除指定行信息,运行结果如图1所示。



图1 通过CheckBox删除选中记录

程序开发步骤如下所示。

(1)新建一个网站,命名为22_01,其主页默认为Default.aspx。

(2)在Default.aspx页面中添加一个Table表格,用来布局页面,然后在该Table表格中添加两个TextBox控件和一个Button控件,分别用来输入管理员姓名、管理员密码和执行登录功能。

(3)在该网站中添加一个Web页面,命名为Manger Page.aspx。在该页中,首先添加一个Table表格,用于布局页面,然后再在该Table表格中添加一个GridView控件、一个CheckBox控件和3个Button控件,分别用来显示用户基本信息、将GridView控件中数据全部选中、执行取消、删除和添加用户信息操作。

(4)主要程序代码如下所示。

当“全选”CheckBox框中选项发生改变时,循环访问GridView控件中的每一项,并使用FindControl方法取得TemplateField模板列中添加的CheckBox控件,然后建立该控件的引用对象,并使用该对象进行操作,实现全选功能。CheckBox控件的CheckedChanged事件代码如下:

protected void CheckBox2_CheckedChanged(object sender, EventArgs e)

{

for (int i = 0; i <= GridView1.Rows.Count-1;i++ )

{

CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");

If (CheckBox2.Checked == True)

{

cbox.Checked = True;

}

else

{

cbox.Checked = False;

}

}

}

单击【全删】按钮时,程序先判断GridView控件中哪些行被选中,并对选中行执行删除操作,然后对GridView控件进行重新绑定,以显示数据表中最新信息。【全删】按钮Click事件代码如下:

protected void btnAllDelete_Click(object sender, EventArgs e)

{

for (int i = 0; i <= GridView1.Rows.Count - 1; i++)

{

CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");

if (cbox.Checked == True)

{

string sqlstr = "delete from tb_Member where MemberID='"+GridView1.DataKeys[i].Value+"'";

SqlConnection myConn = GetConnection();

SqlCommand myCmd = new SqlCommand(sqlstr, myConn);

myConn.Open();

myCmd.ExecuteNonQuery();

myConn.Close();

}

}

bind();

}

完整程序代码如下:

★ ★★★★Default.aspx页面设计文件完整程序代码★★★★★

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>







无标题页









width: 256px; height: 74px" bordercolor="#003333">





管理员姓名:













管理员密码:













&nbsp;

&nbsp;&nbsp;&nbsp;



添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.