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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

aspnet gridview.docx

1、aspnet gridview目录ASP.NETGridView点击行触发SelectedIndexChanged事件 1gridview72般绝技 31.GridView无代码分页排序: 32.GridView选中,编辑,取消,删除: 43.GridView正反双向排序: 104.GridView和下拉菜单DropDownList结合: 15datagridview.Rowsi.DefaultCellStyle.BackColor背景色datagridview.Rowsi.DefaultCellStyle.ForeColor前景色 ASP.NETGridView点击行触发SelectedIn

2、dexChanged事件1、在指令中添加 EnableEventValidation=false2、在RowDataBound事件中添加protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)switch (e.Row.RowType) case DataControlRowType.DataRow: e.Row.Attributesstyle = cursor:hand; #region /点击行触发SelectedIndexChanged事件 PostBackOptions myPostBack

3、Options = new PostBackOptions(this); myPostBackOptions.AutoPostBack = false; myPostBackOptions.PerformValidation = false; myPostBackOptions.RequiresJavaScriptProtocol = true; /加入javascript:头 String evt = Page.ClientScript.GetPostBackClientHyperlink(sender as GridView, Select$ + e.Row.RowIndex.ToStri

4、ng(); e.Row.Attributes.Add(onclick, evt); #endregion break; 3、在第一二步之后就可以在SelectedIndexChanging和SelectedIndexChanged事件中添加处理逻辑了。gridview72般绝技1.GridView无代码分页排序:效果图:1.AllowSorting设为True,aspx代码中是AllowSorting=True;2.默认1页10条,如果要修改每页条数,修改PageSize即可,在aspx代码中是PageSize=12。3.默认的是单向排序的,右击GridView弹出“属性”,选择AllowSo

5、rting为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 System.Web.UI.HtmlControls;usin

6、g 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();protected voidGridView1_RowEditing(object s

7、ender, GridViewEditEventArgs e)GridView1.EditIndex = e.NewEditIndex;bind();/删除protected voidGridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)string sqlstr = delete from 表 where id= +GridView1.DataKeyse.RowIndex.Value.ToString() + ;sqlcon = new SqlConnection(strCon);sqlcom = new SqlComm

8、and(sqlstr,sqlcon);sqlcon.Open();sqlcom.ExecuteNonQuery();sqlcon.Close();bind();/更新protected voidGridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)sqlcon = new SqlConnection(strCon);string sqlstr = update 表 set 字段1=+ (TextBox)(GridView1.Rowse.RowIndex.Cells1.Controls0).Text.ToString().T

9、rim() + ,字段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() + ;sqlcom=new SqlCommand(sqlstr,sqlcon);sqlcon.Open();sqlcom.Execu

10、teNonQuery();sqlcon.Close();GridView1.EditIndex = -1;bind();/取消protected voidGridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)GridView1.EditIndex = -1;bind();/绑定public void bind()string sqlstr = select * from 表;sqlcon = new SqlConnection(strCon);SqlDataAdapter myda = new SqlDa

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

12、uration;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.Data.SqlClient;public partial class Default3 : System.Web.UI.Page/清清月儿的博客SqlConnectio

13、n 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 voidGridView1_Sorting(object sender, GridViewSortEventArgs e)string sPage = e.SortExpression

14、;if (ViewStateSortOrder.ToString() = sPage)if (ViewStateOrderDire.ToString() = Desc)ViewStateOrderDire = ASC;elseViewStateOrderDire = Desc;elseViewStateSortOrder = e.SortExpression;bind();public void bind()string sqlstr = select top 5 * from 飞狐工作室;sqlcon = new SqlConnection(strCon);SqlDataAdapter my

15、da = new SqlDataAdapter(sqlstr, sqlcon);DataSet myds = new DataSet();sqlcon.Open();myda.Fill(myds, 飞狐工作室);DataView view = myds.Tables飞狐工作室.DefaultView;string sort = (string)ViewStateSortOrder + + (string)ViewStateOrderDire;view.Sort = sort;GridView1.DataSource = view;GridView1.DataBind();sqlcon.Clos

16、e();前台主要代码:4.GridView和下拉菜单DropDownList结合:效果图:后台代码: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.HtmlControl

17、s;using System.Data.SqlClient;public partial class Default4 : System.Web.UI.PageSqlConnection sqlcon;string strCon = Data Source=(local);Database=北风贸易;Uid=sa;Pwd=sa;protected void Page_Load(object sender, EventArgs e)DropDownList ddl;if (!IsPostBack)string sqlstr = select top 5 * from 飞狐工作室;sqlcon =

18、 new SqlConnection(strCon);SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);DataSet myds = new DataSet();sqlcon.Open();myda.Fill(myds, 飞狐工作室);GridView1.DataSource = myds;GridView1.DataBind();for (int i = 0; i =GridView1.Rows.Count - 1; i+)DataRowView mydrv = myds.Tables飞狐工作室.DefaultViewi;if

19、(Convert.ToString(mydrv员工性别).Trim() = True)ddl = (DropDownList)GridView1.Rowsi.FindControl(DropDownList1);ddl.SelectedIndex = 0;if (Convert.ToString(mydrv员工性别).Trim() = 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 sqlcom.ExecuteReader();

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

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