我的更新是这样的。 dim mybox as textbox
dim myprice as string
mybox=e.item.findcontrol("price")
myprice=mybox.text
'response.write(myprice)
dim myconn as new oledbconnection(connstr)
dim mycom as oledbcommand
dim sql as string
sql="update guestbook set mynum="& myprice &" where id  = "& (e.item.itemindex) 
mycom=new oledbcommand(sql,myconn)
myconn.open()
mycom.executeNonQuery
myconn.close()
mydatagrid.edititemindex=-1
binddata
这是根据书上的来的,没错,这样是可以执行,但是并不正确。因为id并不一定=e.item.itemindex,比如中间少一条记录就错位了
所以我想问问大家怎样能提出来所在行的id的值。
谢谢。Datagrid中的一部分
<columns>
<asp:boundcolumn datafield="id" headertext="序号" headerstyle-width=50 readonly />

解决方案 »

  1.   

    DATAGRID的属性DataKeyField设置一下,然后可以通过(int)MyDataGrid.DataKeys[(int)e.Item.ItemIndex];获取
      

  2.   

    <asp:DataGrid id="Datagrid1" runat="server" DataKeyField="ID">sql="delete from Category where ID=" & CInt(CType(tmpItem.FindControl("ID"), Label).Text)"
      

  3.   

    非常感谢各位高手哦,成功了。
    但是我想延伸一下假设想更新的条件不是一个条件,而是多个条件,应该怎样?
    比如类似update guestbook where name='xxx' and cateid=5应当如何?谢谢!