




已阅读5页,还剩10页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
查询页面更新删除页面增加页面以下是代码 asp:linkbutton id=cmdfirstpage runat=server commandname=page commandargument=first enabled=首页 asp:linkbutton id=cmdpreview runat=server commandname=page commandargument=prev enabled=前页 第asp:label id=lblcurpage forecolor=blue runat=server text=页/共 asp:label id=lblpagecount forecolor=blue runat=server text=页 asp:linkbutton id=cmdnext runat=server commandname=page commandargument=next enabled=后页 asp:linkbutton id=cmdlastpage runat=server commandargument=last commandname=page enabled=尾页 asp:textbox id=txtgopage runat=server text= width=32px页 -using system;using system.collections.generic;using system.data;using system.data.sqlclient;using system.linq;using system.web;using system.web.configuration;using system.web.ui;using system.web.ui.webcontrols;public partial class _default : system.web.ui.page string constr = webconfigurationmanager.connectionstringsnorthwindconnectionstring.connectionstring; sqlconnection conn; sqlcommand cmd; protected void page_load(object sender, eventargs e) if (!ispostback) conn = new sqlconnection(constr); conn.open(); cmd = new sqlcommand(select distinct age from information, conn); sqldatareader dr = cmd.executereader(); /dropdownlist1数据绑定 dropdownlist1.datasource = dr; dropdownlist1.datatextfield = age; dropdownlist1.databind(); dr.dispose(); conn.dispose(); listitem li = new listitem(全选择, 0); li.selected = true; dropdownlist1.items.add(li); string selectedvalue = dropdownlist1.selectedvalue; if (selectedvalue = 0) bind(); / / 绑定 / private void bind() string selectedvalue = dropdownlist1.selectedvalue; string sqlstr = string.empty; if (selectedvalue = 0) sqlstr = select * from information; else sqlstr = select * from information where age= + selectedvalue + ; conn = new sqlconnection(constr); sqldataadapter dr = new sqldataadapter(sqlstr, conn); dataset ds = new dataset(); conn.open(); dr.fill(ds, information); gridview1.datasource = ds; gridview1.datakeynames = new string id ; gridview1.databind(); conn.close(); / / 查询 / / / protected void btnexecute_click(object sender, eventargs e) bind(); / / 转到zengjia页/ / / protected void button1_click(object sender, eventargs e) response.redirect(zengjia.aspx); / / 取消编辑 / / / protected void gridview1_rowcancelingedit(object sender, gridviewcancelediteventargs e) gridview1.editindex = -1; bind(); / / 编辑 / / / protected void gridview1_rowediting(object sender, gridviewediteventargs e) gridview1.editindex = e.neweditindex; bind(); / / 更新 / / / protected void gridview1_rowupdating(object sender, gridviewupdateeventargs e) textbox text1 = (textbox)(gridview1.rowse.rowindex.cells1.controls0); textbox text2 = (textbox)(gridview1.rowse.rowindex.cells2.controls0); textbox text3 = (textbox)(gridview1.rowse.rowindex.cells3.controls0); textbox text4 = (textbox)(gridview1.rowse.rowindex.cells4.controls0); if (string.isnullorempty(text1.text) response.write(alert(请输入姓名);); return; if (string.isnullorempty(text2.text) response.write(alert(请输入年龄); return; else try int tmp = int.parse(text2.text); catch (exception) response.write(alert(请输入年龄); return; if (string.isnullorempty(text3.text) response.write(alert(请输入地址); return; if (string.isnullorempty(text4.text) response.write(alert(请输入电话号码); return; else if (text4.text.length 11 | text4.text0 = 0) response.write(alert(请输入电话号码); return; else try int64 tmp = int64.parse(text4.text); catch (exception) response.write(alert(请输入电话号码); return; try int ageer = convert.toint32(textbox)(gridview1.rowse.rowindex.cells2.controls0).text.tostring().trim(); conn = new sqlconnection(constr); string sqlstr = update information set name= + (textbox)(gridview1.rowse.rowindex.cells1.controls0).text.tostring().trim() + ,age= + (textbox)(gridview1.rowse.rowindex.cells2.controls0).text.tostring().trim() + ,address= + (textbox)(gridview1.rowse.rowindex.cells3.controls0).text.tostring().trim() + ,phone= + (textbox)(gridview1.rowse.rowindex.cells4.controls0).text.tostring().trim() + where id= + (gridview1.rowse.rowindex.cells0).text.tostring().trim() + ; cmd = new sqlcommand(sqlstr, conn); conn.open(); cmd.executenonquery(); conn.close(); gridview1.editindex = -1; bind(); catch return; /通过跳转页面传递数据id 更新数据 /conn = new sqlconnection(constr); / string id = select id from id where id= + (gridview1.rowse.rowindex.cells0).text.tostring().trim() + ; /response.redirect(zengjia.aspx?id= + (gridview1.rowse.rowindex.cells0).text.tostring().trim() + ); / / 删除 / / / protected void gridview1_rowdeleting(object sender, gridviewdeleteeventargs e) conn=new sqlconnection(constr); string sqlstr=delete from information where id=+ (gridview1.rowse.rowindex.cells0).text.tostring().trim()+; cmd = new sqlcommand(sqlstr, conn); conn.open(); cmd.executenonquery(); conn.close(); gridview1.editindex = -1; bind(); / / 分页 / / / protected void gridview1_pageindexchanging(object sender, gridviewpageeventargs e) gridview1.pageindex = e.newpageindex; bind(); / / 跳转 / / / protected void turn_click(object sender, eventargs e) gridview1.pageindex = int.parse(textbox)gridview1.bottompagerrow.findcontrol(txtgopage).text) - 1; bind(); using system;using system.collections.generic;using system.linq;using system.web;using system.web.ui;using system.web.ui.webcontrols;using system.data;using system.data.sqlclient;using system.web.configuration;using system.text.regularexpressions;public partial class zengjia : system.web.ui.page string constr = webconfigurationmanager.connectionstringsnorthwindconnectionstring.connectionstring; protected void page_load(object sender, eventargs e) /接收传递过来的数据id查询数据绑定到textbox上 再进行更新 /if (!ispostback) / / if (request.querystringid != null) / / button1.text = 更新; / sqlconnection conn = new sqlconnection(constr); / sqlcommand cmd = new sqlcommand(select*from information where id= + request.querystringid+, conn); / conn.open(); / sqldatareader dr = cmd.executereader(commandbehavior.closeconnection); / while (dr.read() / / this.textbox1.text = drname.tostring(); / this.textbox2.text = drage.tostring(); / this.textbox3.text = draddress.tostring(); / this.textbox4.text = drphone.tostring(); / / / / / 增加 / / / protected void button1_click(object sender, eventargs e) /判断用户输入 if (string.isnullorempty(textbox1.text) response.write(alert(请输入姓名); return; if (string.isnullorempty(textbox2.text) response.write(alert(请输入年龄); return; else try int tmp = int.parse(textbox2.text); catch (exception) response.write(alert(请输入年龄); return; if (string.isnullorempty(textbox3.text) response.write
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 浙江省金华市兰溪市2024-2025学年七年级下学期期末考试英语试题(含笔试答案无听力)
- 福鼎白茶知识培训课件
- 腾讯笔试题及答案
- 蚌埠成考试题及答案
- 8Z-11Z-14Z-17Z-20Z-23Z-Hexacosahexaenoyl-CoA-8Z-11Z-14Z-17Z-20Z-23Z-Hexacosahexaenoyl-coenzyme-A-生命科学试剂-MCE
- DB61T 531-2011 土工膜复合半圆排水管通 用技术条件
- DB61T 506.7-2024 城市轨道交通自动售检票系统技术规范 第7部分:人机界面
- 陕西省西安市蓝田县2025-2026学年高三数学第一学期期末教学质量检测模拟试题
- 重庆市主城区七校联考2025-2026学年数学高三第一学期期末质量跟踪监视试题
- 浙江诸暨中学2025年数学高三上期末质量跟踪监视试题
- 公众责任保险附加电梯责任保险
- 儿童智能玩具调研报告
- 广州知识产权法院民事判决书
- 供配电技术基本知识课件
- 应急信息报送制度
- 铁道车辆构造与检修高职PPT完整全套教学课件
- 铜矿石买卖合同(标准版)
- 浙人美2011版四年级美术上册《水资源》教案及教学反思
- 西餐烹调工艺与实训PPT全套完整教学课件
- 2023年高等教育文学类自考-03297企业文化考试参考题库(含答案)
- 北京市建筑施工作业人员安全生产知识教育培训考核试卷(A-B-C-D-E)【完整版】
评论
0/150
提交评论