




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
GridView控件自定义分页详解在这里我们将用一个隐藏字段来保存这个PageIndex,即当前页码.当点击上一页时,将它的值减一,知道为0,要注意的一点这里的第一页页码是0而不是1.下面看看代码,然后我们再分析分析!12 3 4 6 7 9 10 11 12 13 首 页14 上一页15 下一页16 尾 页17 CS文件中的代码:1 protected void PagerButton_Click(object sender, EventArgs e)2 3 int pageIndx = Convert.ToInt32(CurrentPage.Value);4 int totals = NewsManager.GetNews(0, pageSize).TotalRecords;5 int pages = (totals % pageSize) = 0 ? (totals / pageSize) : (totals / pageSize + 1);6 string arg = (LinkButton)sender).CommandArgument.ToString().ToLower();7 switch (arg)8 9 case prev:10 if (pageIndx 0)11 12 pageIndx -= 1;13 14 break;15 case next:16 if (pageIndx pages - 1)17 18 pageIndx += 1;19 20 break;21 case last:22 pageIndx = pages - 1;23 break;24 default:25 pageIndx = 0;26 break;27 28 CurrentPage.Value = pageIndx.ToString();29 NewsGrid.DataSource = NewsManager.GetNews(pageIndx , pageSize).Entities;30 NewsGrid.DataBind();31 如何在GridView中增加效果protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) /将满足特定条件的行标为高亮 if (e.Row.RowType = DataControlRowType.DataRow)/判定当前的行是否属于datarow类型的行 int money = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, MONEY);/取当前行的列值 if (money = 77) e.Row.BackColor = Color.Red; /string customer = (string)DataBinder.Eval(e.Row.DataItem, CUSTOMER); string customer = DataBinder.Eval(e.Row.DataItem, CUSTOMER).ToString(); if (customer = sdf) e.Row.BackColor = Color.Red; /加入鼠标滑过的高亮效果 if (e.Row.RowType = DataControlRowType.DataRow)/判定当前的行是否属于datarow类型的行 /当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 e.Row.Attributes.Add(onmouseover, currentcolor=this.style.backgroundColor;this.style.backgroundColor=yellow,this.style.fontWeight=;); /当鼠标离开的时候 将背景颜色还原的以前的颜色 e.Row.Attributes.Add(onmouseout, this.style.backgroundColor=currentcolor,this.style.fontWeight=;); /单击行改变行背景颜色 if (e.Row.RowType = DataControlRowType.DataRow) e.Row.Attributes.Add(onclick,this.style.backgroundColor=#99cc00; this.style.color=buttontext;this.style.cursor=default;); 如何在GridView中一次性批量更新多行数据ASP.NET2.0下含有DropDownList的GridView编辑、删除的完整例子! %-asp:TextBox ID=TextBox1 runat=server Text=-% asp:DropDownList ID =ddlXL runat=server DataValueField= asp:Label ID=Label1 runat=server Text= asp:TextBox ID=TextBox2 runat=server Text= asp:Label ID=Label2 runat=server Text= / / 绑定数据到GridView / private void GridViewBind() 检索数据库 string strSql = SELECT * FROM DB1; 得到数据集 this.GridView1.DataSource=conn.GetDs(strSql).Tables0.DefaultView; this.GridView1.DataBind(); / / 编辑当前行 / / / protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) GridView1.EditIndex = e.NewEditIndex; /当前编辑行背景色高亮 this.GridView1.EditRowStyle.BackColor = Color.FromName(#F7CE90); GridViewBind(); / / 取消编辑状态 / / / protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) GridView1.EditIndex = -1; GridViewBind(); / / 删除记录过程 / / / protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) /得到单位编号 string rowToDelete = GridView1.DataKeyse.RowIndex.Values0.ToString(); /转换为整数 /int ID=Convert.ToInt32(rowToDelete); /从数据库中删除 string str = DELETE FROM DB1 where DB1_1= + + rowToDelete + + ; try conn.RunSql(str); /重新绑定数据 GridViewBind(); catch (Exception ex) Response.Write(数据库错误,错误原因: + ex.Message); Response.End(); / / 更新记录过程 / / / protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) string ID = GridView1.DataKeyse.RowIndex.Values0.ToString(); string DB1_1 = (TextBox)GridView1.Rowse.RowIndex.FindControl(TextBox1).Text; /string DB1_2 = (TextBox)GridView1.Rowse.RowIndex.FindControl(TextBox2).Text; string DB1_2 = (DropDownList)GridView1.Rowse.RowIndex.FindControl(ddlXL).SelectedItem.Text; /判断表单项是否有空并给出提示信息 if (DB1_1 = | DB1_2 = ) conn.Alert(请输入完整信息!, Page); return; try conn.BuilderEdit(select * from DB1 where DB1_1 = + ID + ); conn.drDB1_1 = DB1_1; conn.drDB1_2 = DB1_2; conn.BuilderEditClose(); catch (OracleException err) if (err.Code.ToString() = 1) conn.Alert(错误:已存在具有相同主键的记录, Page); else conn.Alert(错误:未能添加记录, Page); Response.Write(alert(数据已被保存!);); /返回浏览状态 GridView1.EditIndex = -1; GridViewBind(); / / 分页事件 / / / protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) GridView1.PageIndex = e.NewPageIndex; GridViewBind(); / / 加入鼠标效果及为DropDownList绑定值 / / / protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) /为DropDownList绑定值 if (DropDownList)e.Row.FindControl(ddlXL) != null) DropDownList ddlXL = (DropDownList)e.Row.FindControl(ddlXL); ddlXL.Items.Clear(); ddlXL.Items.Add(new ListItem(博士, 1); ddlXL.Items.Add(new ListItem(硕士, 2); ddlXL.Items.Add(new ListItem(学士, 3); /加入鼠标滑过的高亮效果 if (e.Row.RowType = DataControlRowType.DataRow)/判定当前的行是否属于datarow类型的行 /当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 e.Row.Attributes.Add(onmouseover, currentcolor=this.style.backgroundColor;this.style.backgroundColor=yellow,this.style.fontWeight=;); /当鼠标离开的时候 将背景颜色还原的以前的颜色 e.Row.Attributes.Add(onmouseout, this.style.backgroundColor=currentcolor,this.style.fontWeight=;); /单击行改变行背景颜色 if (e.Row.RowType = DataControlRowType.DataRow) e.Row.Attributes.Add(onclick, this.style.backgroundColor=#99cc00; this.style.color=buttontext;this.style.cursor=default;); ASP.NET2.0下含有CheckBox的GridView删除选定记录实例4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 20 21 22 23 1 2 1 protected void btnDelete_Click(object sender, EventArgs e)2 3 string strDelete = ;4 for (int i = 0; i this.GridView1.Rows.Count; i+)5 6 string Label;7 bool isChecked = (CheckBox)GridView1.Rowsi.FindControl(chkSelect).Checked;8 Label = (Label)GridView1.Rowsi.FindControl(labXH).Text;9 if (isChecked)10 11 strDelete = DB1_1 + = + Label;12 13 14 conn.RunSql(Delete from DB1 where + strDelete 15 this.chkSelectA
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年武清数学中考试题及答案
- 智算中心计算任务调度与管理方案
- 水体景观设计与水质管理方案
- 机电设备安装过程风险评估与控制方案
- 汽车八级考试题目及答案
- 产后恶露考试试题及答案
- 广告制作安装合同
- 广东省2024年普通高中学业水平合格性考试思想政治考试题目及答案
- 互联网医疗平台员工劳动合同及医疗数据保密协议
- 知识产权竞业禁止协议赔偿金计算与执行细则
- 车队管理培训课件模板
- 内蒙古呼伦贝尔农垦集团有限公司招聘笔试题库及答案详解(历年真题)
- 2025年省农垦集团有限公司人员招聘笔试备考附答案详解(完整版)
- 基于核心素养的幼儿园教学评价体系
- 2025至2030中国X光安检机行业项目调研及市场前景预测评估报告
- 2025年市中区畜牧兽医、动物检疫站事业单位招聘考试真题库及答案
- 幼儿园小班数学活动《认识1和许多》课件
- 《HJ 212-2025 污染物自动监测监控系统数据传输技术要求》
- DZ∕T 0215-2020 矿产地质勘查规范 煤(正式版)
- 电厂确保稳定运行技术措施
- 殡葬资格考试:殡葬服务试题及答案
评论
0/150
提交评论