Sub DataGrid2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles Datagrid2.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim DDL As DropDownList = e.Item.FindControl("picclass")
web.connopen()
'获得原来绑定的分类名称
cmd = New OleDb.OleDbCommand("select Class from picclass where ID=" & e.Item.Cells(0).Text, web.conn)
dr = cmd.ExecuteReader
Dim oldclass As String
While dr.Read
oldclass = dr.Item(0)
End While
提示ID=后面是空的~~~为什么?ID我是用的BoundColumn绑定的~
Handles Datagrid2.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim DDL As DropDownList = e.Item.FindControl("picclass")
web.connopen()
'获得原来绑定的分类名称
cmd = New OleDb.OleDbCommand("select Class from picclass where ID=" & e.Item.Cells(0).Text, web.conn)
dr = cmd.ExecuteReader
Dim oldclass As String
While dr.Read
oldclass = dr.Item(0)
End While
提示ID=后面是空的~~~为什么?ID我是用的BoundColumn绑定的~
我觉得如果你要拿到控件的id的话应该这样吧e.Item.Cells[0].Controls[0].ID
<asp:datagrid DataKeyField="menu_id">
在绑定中
string id = DataGrid1.DataKeys[e.item.ItemIndex].ToString();