♣
在web控件datagrid里面怎么样才能对表格进行编辑。加入文本框textbox控件如何加入!
如题目所问。
· 网友精彩回答:
不知下段代码对你是否有帮助,编辑时datagrid会自动添加textbox控件
<%@ import namespace="system.data.oledb" %>
<script language="vb" runat=server>
定义全局变量myconnection
dim myconnection as oledbconnection
dim mycommand as oledbcommand
sub page_load(sender as object, e as eventargs)
dim strcnn as string="provider=microsoft.jet.oledb.4.0; "& _
"data source=e:/source/db/学生.mdb"
myconnection=new oledbconnection(strcnn)
myconnection.open
if(not page.ispostback)
call bindgrid
end if
end sub
sub bindgrid()
dim strsql as string="select * from 基本情况"
mycommand=new oledbcommand(strsql,myconnection)
dim mydatareader as oledbdatareader
mydatareader=mycommand.executereader()
mydatagrid.datasource=mydatareader
mydatagrid.databind
end sub
private sub datagrid_edit(sender as object,e as datagridcommandeventargs)
mydatagrid.edititemindex=e.item.itemindex
call bindgrid
end sub
private sub datagrid_cancel(sender as object,e as datagridcommandeventargs)
mydatagrid.edititemindex = -1
call bindgrid
end sub
private sub datagrid_update(sender as object,e as datagridcommandeventargs)
dim id,语文,数学,英语 as string
dim strsql as string
dim temptextbox as textbox
id=e.item.cells(1).text
temptextbox=e.item.cells(3).controls(0)
语文=temptextbox.text
temptextbox=e.item.cells(4).controls(0)
数学=temptextbox.text
temptextbox=e.item.cells(5).controls(0)
英语=temptextbox.text
strsql="update 基本情况 set chinese=" & 语文 & ",math=" & 数学 & ",english=" & 英语 & " where id=" & id & ""
dim mycommand as oledbcommand=new oledbcommand
mycommand.connection=myconnection
mycommand.commandtext=strsql
mycommand.executenonquery()
mydatagrid.edititemindex = -1
call bindgrid
end sub
</script>
<html>
<title>演示editcommandcolumn</title>
</head>
<body>
<form runat=server>
<center>
<p>演示editcommandcolumn</p>
<asp:datagrid id="mydatagrid" runat="server"
autogeneratecolumns="false"
oneditcommand="datagrid_edit"
oncancelcommand="datagrid_cancel"
onupdatecommand="datagrid_update" >
<columns>
<asp:editcommandcolumn headertext="" buttontype="pushbutton"
edittext="编辑"
updatetext="更新"
canceltext="取消" />
<asp:boundcolumn headertext="学号" datafield="id" readonly="true" />
<asp:boundcolumn headertext="姓名" datafield="name" readonly="true" />
<asp:boundcolumn headertext="语文成绩" datafield="chinese" />
<asp:boundcolumn headertext="数学成绩" datafield="math" />
<asp:boundcolumn headertext="英语成绩" datafield="english" />
</columns>
</asp:datagrid>
</center>
</form>
</body>
</html>
其实这个问题也很好办,在datagrid里有,editcommand行为,指要你在它的里面指定datagrid进入编辑模式就行了,如:
private void edit_event(object source, system.web.ui.webcontrols.datagridcommandeventargs e)
{
yourdatagrid.edititemindex = e.item.itemindex;
yourdatagriddatabind();
}
然后private void initializecomponent()
{
this.dgnavigation.editcommand += new system.web.ui.webcontrols.datagridcommandeventhandler(this.edit_event);
this.load += new system.eventhandler(this.page_load);
}
挂勾上,你就可以编辑了,library上说得很清楚你可以查查~
- 更多问题:
- · 大家感到痛心的话就多转发几个地方,这在东莞白天发生的抢劫....
- · VB 中怎么把JPG文件转化成BMP文件
- · 想装一台电脑,5000块左右,谁能给个建议啊?谢谢
- · 做数据库管理员是否适合自学?
- · 小第有个问题要发问???
- · 郁闷,心烦,不能静心学习!求救!
- · 显示不出验证码
- · 如何把本地的图片加到一个Fram中显示
- · JAVA实现监控局域网中其他计算机运行状况!
- · 质疑一次编译到处运行
- · 求助:在XP下面怎样设置数据库(access)文件夹的写入权限?
- · 如何使用Apache的HSSF(POI)来写上万行的Excel报表
- · 论坛发帖与跟贴的原理
- · 爆难算法题一 据说北京某名牌大学全军覆没 大家讨论下
- · [请教]VB.NET中的参数传递的问题?
- · 如何使用Apache的HSSF(POI)来写上万行的Excel报表
- · XHTML技术文档
- · RedHat专题 | RedHat
- · JPEG技术文档
- · IEEE技术文档
- · CGI专题 | CGI
- · Perl专题
- · ntfs文件
- · 入侵xp
- · 改mac
- · dns查询
- · ip mac
- · 打开pdf
- · borland 分家
- · 修改bios
- · 后门端口
- · 亿域
- · 在vc6.0 or .net里面使用ado功能
- · auto病毒,怎么清除
- · 瑞星病毒库
- · 卡巴斯基最新病毒库更新地址
- · 卡巴斯基病毒库更新
- · 下载魔波病毒补丁后桌面图标消失
- · 灰鸽子病毒手工清除方法
- · 病毒性感冒

