ImageVerifierCode 换一换
格式:DOCX , 页数:44 ,大小:299.21KB ,
资源ID:3442939      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3442939.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(GridView 经典例子19个.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

GridView 经典例子19个.docx

1、GridView 经典例子19个GridView 经典例子19个快速预览:GridView无代码分页排序GridView选中,编辑,取消,删除GridView正反双向排序GridView和下拉菜单DropDownList结合GridView和CheckBox结合鼠标移到GridView某一行时改变该行的背景色方法一鼠标移到GridView某一行时改变该行的背景色方法二GridView实现删除时弹出确认对话框GridView实现自动编号GridView实现自定义时间货币等字符串格式GridView实现用“.”代替超长字符串GridView一般换行与强制换行GridView显示隐藏某一列GridV

2、iew弹出新页面/弹出新窗口GridView固定表头(不用javascript只用CSS,2行代码,很好用)GridView合并表头多重表头无错完美版(以合并3列3行举例)GridView突出显示某一单元格(例如金额低于多少,分数不及格等)GridView加入自动求和求平均值小计GridView数据导入Excel/Excel数据读入GridView1.GridView无代码分页排序:1.AllowSorting设为True,aspx代码中是AllowSorting=True;2.默认1页10条,如果要修改每页条数,修改PageSize即可,在aspx代码中是PageSize=12。3.默认的是

3、单向排序的,右击GridView弹出“属性”,选择AllowSorting为True即可。2.GridView选中,编辑,取消,删除:后台代码:你可以使用sqlhelper,本文没用。代码如下: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 Sys

4、tem.Web.UI.HtmlControls;using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page /清清月儿 SqlConnection sqlcon; SqlCommand sqlcom; string strCon = Data Source=(local);Database=数据库名;Uid=帐号;Pwd=密码; protected void Page_Load(object sender, EventArgs e) if (!IsPostBack) bind(); protect

5、ed void GridView1_RowEditing(object sender, GridViewEditEventArgs e) GridView1.EditIndex = e.NewEditIndex; bind(); /删除 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) string sqlstr = delete from表 where id= + GridView1.DataKeyse.RowIndex.Value.ToString() + ; sqlcon = ne

6、w SqlConnection(strCon); sqlcom = new SqlCommand(sqlstr,sqlcon); sqlcon.Open(); sqlcom.ExecuteNonQuery(); sqlcon.Close(); bind(); /更新 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) sqlcon = new SqlConnection(strCon); string sqlstr = update 表 set 字段1= + (TextBox)(GridV

7、iew1.Rowse.RowIndex.Cells1.Controls0).Text.ToString().Trim() + ,字段2= + (TextBox)(GridView1.Rowse.RowIndex.Cells2.Controls0).Text.ToString().Trim() + ,字段3= + (TextBox)(GridView1.Rowse.RowIndex.Cells3.Controls0).Text.ToString().Trim() + where id= + GridView1.DataKeyse.RowIndex.Value.ToString() + ; sql

8、com=new SqlCommand(sqlstr,sqlcon); sqlcon.Open(); sqlcom.ExecuteNonQuery(); sqlcon.Close(); GridView1.EditIndex = -1; bind(); /取消 protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) GridView1.EditIndex = -1; bind(); /绑定 public void bind() string sqlstr = select *

9、from 表; sqlcon = new SqlConnection(strCon); SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon); DataSet myds = new DataSet(); sqlcon.Open(); myda.Fill(myds, 表); GridView1.DataSource = myds; GridView1.DataKeyNames = new string id ;/主键 GridView1.DataBind(); sqlcon.Close(); 前台主要代码: . . 3.GridView

10、正反双向排序:效果图:点姓名各2次的排序,点其他也一样可以。后台代码:using System;using System.Data;using System.Configuration;using System.Collections;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.

11、Data.SqlClient;public partial class Default3 : System.Web.UI.Page/清清月儿的博客 SqlConnection sqlcon; string strCon = Data Source=(local);Database=北风贸易;Uid=sa;Pwd=; protected void Page_Load(object sender, EventArgs e) if (!IsPostBack) ViewStateSortOrder = 身份证号码; ViewStateOrderDire = ASC; bind(); protected

12、 void GridView1_Sorting(object sender, GridViewSortEventArgs e) string sPage = e.SortExpression; if (ViewStateSortOrder.ToString() = sPage) if (ViewStateOrderDire.ToString() = Desc) ViewStateOrderDire = ASC; else ViewStateOrderDire = Desc; else ViewStateSortOrder = e.SortExpression; bind(); public v

13、oid bind() string sqlstr = select top 5 * from 飞狐工作室; sqlcon = new SqlConnection(strCon); SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon); DataSet myds = new DataSet(); sqlcon.Open(); myda.Fill(myds, 飞狐工作室); DataView view = myds.Tables飞狐工作室.DefaultView; string sort = (string)ViewStateSortOr

14、der + + (string)ViewStateOrderDire; view.Sort = sort; GridView1.DataSource = view; GridView1.DataBind(); sqlcon.Close(); 前台主要代码: 4.GridView和下拉菜单DropDownList结合:后台代码:using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using Syst

15、em.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Data.SqlClient;public partial class Default4 : System.Web.UI.Page SqlConnection sqlcon; string strCon = Data Source=(local);Database=北风贸易;Uid=sa;Pwd=sa; protected void Pag

16、e_Load(object sender, EventArgs e) DropDownList ddl; if (!IsPostBack) string sqlstr = select top 5 * from 飞狐工作室; sqlcon = new SqlConnection(strCon); SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon); DataSet myds = new DataSet(); sqlcon.Open(); myda.Fill(myds, 飞狐工作室); GridView1.DataSource = m

17、yds; GridView1.DataBind(); for (int i = 0; i = GridView1.Rows.Count - 1; i+) DataRowView mydrv = myds.Tables飞狐工作室.DefaultViewi; if (Convert.ToString(mydrv员工性别).Trim() = True) ddl = (DropDownList)GridView1.Rowsi.FindControl(DropDownList1); ddl.SelectedIndex = 0; if (Convert.ToString(mydrv员工性别).Trim()

18、 = False) ddl = (DropDownList)GridView1.Rowsi.FindControl(DropDownList1); ddl.SelectedIndex = 1; sqlcon.Close(); public SqlDataReader ddlbind() string sqlstr = select distinct 员工性别 from 飞狐工作室; sqlcon = new SqlConnection(strCon); SqlCommand sqlcom = new SqlCommand(sqlstr, sqlcon); sqlcon.Open(); return sqlc

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1