估计这是DataGrid的itemCommand事件吧,避免e.Item.ItemIndex等于-1,因为翻页、排序等事件同样可以触发itemCommand Sub MyDataGrid_Update(sender As Object, e As DataGridCommandEventArgs) if e.Item.ItemIndex>-1 then .... end if end sub
Dim ds As New DataSet Cstring = "SELECT id,factory as col1,workorder as col2,FD as col3,FDDescribe as col4,FDQuantity as col5," Cstring = Cstring + "line as col6,depot as col7,depotposition as col8,nc as col9,ncDescribe as col10," Cstring = Cstring + "ncQuantity as col11,QtPerBk as col12,unit as col13,riqi as col14 from material" Dim da As SqlDataAdapter = New SQLDataAdapter(Cstring,Conn) da.fill(ds,"material") MyDataGrid.DataSource = ds.Tables("material").defaultview MyDataGrid.DataBind() Conn.Close() panel2.visible = true MyDataGrid.visible = true 还有注意空格
Sub MyDataGrid_Update(sender As Object, e As DataGridCommandEventArgs)
if e.Item.ItemIndex>-1 then
....
end if
end sub
你的MyDataGrid.DataKeys()有没有这么多呀,你跟踪调试一下
Cstring = "SELECT id,factory as col1,workorder as col2,FD as col3,FDDescribe as col4,FDQuantity as col5,"
Cstring = Cstring + "line as col6,depot as col7,depotposition as col8,nc as col9,ncDescribe as col10,"
Cstring = Cstring + "ncQuantity as col11,QtPerBk as col12,unit as col13,riqi as col14 from material"
Dim da As SqlDataAdapter = New SQLDataAdapter(Cstring,Conn)
da.fill(ds,"material")
MyDataGrid.DataSource = ds.Tables("material").defaultview
MyDataGrid.DataBind()
Conn.Close()
panel2.visible = true
MyDataGrid.visible = true
还有注意空格