| 发表于:2007-06-17 16:56:00 楼主 |
下边一段代码是按照教材上抄下来的 <%@ page language= "c# " contenttype= "text/html " responseencoding= "gb2312 " %> <%@ import namespace= "system.data " %> <%@ import namespace= "system.data.oledb " %> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en " "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd "> <html xmlns= "http://www.w3.org/1999/xhtml " > <head runat= "server "> <script runat=server> oledbconnection myconn; public void page_load(object sender, eventargs e) { // 连接语句 string myconnstring = "provider=microsoft.jet.oledb.4.0;data source= " + server.mappath( ". ") + "..\\data\\score.mdb; "; myconn = new oledbconnection(myconnstring); myconn.open(); if (!page.ispostback) { bindgrid(); } } //创建当前数据的默认视图 icollection createtable() { string strsel = "select * form score "; oledbdataadapter myadapter = new oledbdataadapter(strsel, myconn); dataset ds = new dataset(); myadapter.fill(ds, "table1 "); return ds.tables[ "table1 "].defaultview; } //处理edit命令 public void datagrid_editcommand(object sender, datagridcommandeventargs e) { table1.edititemindex = (int)e.item.itemindex; bindgrid(); } //处理cancel命令 public void datagird_cancelcommand(object sender, datagridcommandeventargs e) { table1.edititemindex = -1; bindgrid(); } //处理update命令 public void datagrid_updatecommand(object sender, datagridcommandeventargs e) { //取得已更新数据 string strname = e.item.cells[1].text; int intmath = int32.parse(((textbox)e.item.cells[2].controls[0]).text); int intenglish = int32.parse(((textbox)e.item.cells[3].controls[0]).text); int intchinese = int32.parse(((textbox)e.item.cells[4].controls[0]).text); //更新数据库 string strupdate= "update table1 set s_math= "+intmath+ ",s_english= "+intenglish+ ",s_chinese= "+intchinese+ " where s_name= ' "+strname+ " ' "; oledbcommand mycommand = new oledbcommand(strupdate, myconn); mycommand.EXECutenonquery(); table1.edititemindex = -1; bindgrid(); } </script> <title> editcommandcolumn </title> </head> <body> <form id= "form1 " runat= "server "> <div> <asp:datagrid id= "table1 " runat=server headerstyle-backcolor= "#aaaadd " alternatingitemstyle-backcolor= "#addeae " autogeneratecolumns=false oneditcommand= "datagrid_editcommand " oncancelcommand= "datagrid_cancelcommand " onupdatecommand= "datagrid_updatecommand "> <columns> <asp:editcommandcolumn headertext= "play area " edittext= "edit " canceltext= "cancel " updatetext= "update " buttontype= "pushbutton "/> <asp:boundcolumn headertext= "name " datafield= "s_name " readonly=true/> <asp:boundcolumn headertext= "math " datafield= "s_math "/> <asp:boundcolumn headertext= "english " datafield= "s_english "/> <asp:boundcolumn headertext= "chinese " datafield= "s_chinese "/> </columns> </asp:datagrid> </div> </form> </body> </html> 出错提示如下: 编译错误 说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: cs0103: 当前上下文中不存在名称“bindgrid” 源错误: 行 18: if (!page.ispostback) 行 19: { 行 20: bindgrid(); 行 21: } 我自己搜了一个下午了,也没找到问题所在,麻烦指点一下,非常感谢 |
|
|
|
|