Well... it's not so easy as it seemed to be
It requires a little bit of hack...
Here we go
The problem you had is that you cannot access to the selecteditem in the itemdatabound event... I thought this was possible but it seems to not
So to fix this, first, add the OnSelectedIndexChanged handler to the ddl (this is the one who see the value of the selected item)
Now change the onitemdatabound with the old one you had:
Public Sub eventItemDataBound1(ByVal S As Object, ByVal objArgs As DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim drop1 As DropDownList = objArgs.Item.FindControl("myDDL")
Dim myDataSet As DataSet
Dim myDataTable As DataTable
myDataSet = CType(Session("data"), DataSet)
myDataTable = myDataSet.Tables("Tabel")
Dim myDataView As DataView
myDataView = New DataView(myDataTable)
drop1.DataSource = myDataView
drop1.DataMember = "Tabel"
drop1.DataTextField = "aantal"
drop1.DataValueField = "aantal"
drop1.DataBind()
' add this to initialize the third column with the value 1 (or write it derectly on the aspx)
e.Item.Cells[2].Text = 1;
end If
End Sub
And finally write this to the onselectedindexchanegd handler
Public Sub ddl_change(object sender, System.EventArgs e)
Dim ddl as DropDownList = Ctype(sender, DropDownList)
' get the datagrid item being used bounded. Note that is the parent of the parent of the ddl
Dim dgi As DataGridItem = Ctype(ddl.Parent.Parent, DataGridItem)
dgi.Cells[2].Text = ddl.SelectedItem.Value
End sub
this is a hack but works... the problem is that teh databound event is being fired before the ddl change. If not you could store the selected
item in a public var and use it in the databound event