DataGrid 得不到要update的数据
在DataGrid上面点击“编辑”后,在出现的textbox中输入数据,之后点击“更新”,但是通过
e.Item.Cells(4).Text
不能够得到编辑筐中的数据
但是在点击“编辑”的时候e.Item.Cells(4).Text能够得到数据啊
lsSQL = "update spi_log set isno='" & e.Item.Cells(4).Text & "' where rowid='" & e.Item.Cells(e.Item.Cells.Count - 1).Text & "'"
问题点数:100、回复次数:9Top
1 楼cgipro(迷途)回复于 2005-06-03 17:52:50 得分 0
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim lsSQL As String
lsSQL = "update spi_log set isno='" & e.Item.Cells(4).Text & "' where rowid='" & e.Item.Cells(e.Item.Cells.Count - 1).Text & "'"
ado.ExecSQL(lsSQL)
DataGrid1.EditItemIndex = -1
setDataBind()
End SubTop
2 楼LoveCherry(论成败,人生豪迈;大不了,重头再来!^_^)回复于 2005-06-03 17:55:22 得分 10
http://www.cnblogs.com/lovecherry/archive/2005/03/25/125487.htmlTop
3 楼hchxxzx(NET?摸到一点门槛)回复于 2005-06-03 17:59:46 得分 20
你这样是得不到值的.
点击编辑的时候,控件出现的是输入框,而你却取列值,肯定有问题.
你应该用模板列来达到编辑的目的.
你可参看如下地址的完整datagrid编辑示例代码
http://community.csdn.net/Expert/TopicView.asp?id=4016964Top
4 楼luckyprg(lucky)回复于 2005-06-03 18:26:52 得分 0
你更新后没有重新绑定数据源吧?
检查一下
setDataBind()Top
5 楼cgipro(迷途)回复于 2005-06-03 18:30:47 得分 0
To: LoveCherry
我用的是Oracle,你的代码是针对sqlserver的,不能用吧Top
6 楼cgipro(迷途)回复于 2005-06-03 19:15:07 得分 0
a = e.Item.Cells(2).Controls(0)
s = a.Text
这样是可以的,VB好像没有强制类型转化Top
7 楼fanglibang(小久)回复于 2005-06-04 13:36:16 得分 10
上楼是对的。。
a = e.Item.Cells(2).Controls(0)用这个得到值,这个字段要设为可编辑模式 :
a = e.Item.Cells(2).text用这个得到的值,这个字段 要设为不可编辑模式:也就是只读
Top
8 楼jerry_yuan(jerry)回复于 2005-06-04 13:42:18 得分 30
ctype(e.Item.Cells(2).Controls(0),TextBox).textTop
9 楼yc3231996(阿蒙)回复于 2005-06-04 13:51:40 得分 30
点了编辑后,那一列里出项的是个textbox控件,当然不能用e.Item.Cells(4).Text来获得值
用e.item.cell(i).controls(0)可以引用到所单击行的第i列的第一个控件
再把该控件转为textbox类型就可以取其值
agree jerry_yuan(jerry)
用ctype(e.Item.Cells(2).Controls(0),TextBox).text取值Top




