I followed this site and I got it to work as the site shows -
http://aspalliance.com/142_Working_w...s_in_DataGrids
However, with my scenario I need to figure out how to take the ID from the datalist and pass it to my Function:
<asp:DropDownList id="ddlSizes"
DataSource="<%# BindSize(DataBinder.Eval(Container.DataItem, "ID")) %>"
This returns a malformed syntax error for the aspx page.
Basically I'm returning a lot of data that has specific data associated with it and I want to dump that data in a DropDownList.
If it can be handled in the codebehind that would be best but when I try that I get "object reference not set to an instance of an object..." for my DDL.
Code Behind attempt:
Page_Load
list.DataSource = datalayer.GetProducts()
list.DataBind()
BindSizes(list.DataKeyField) 'list.DataKeyField is wrong... I can't figure out how to send the ID.
Private Sub BindSizes(ByVal productId As String)
Dim connection As New OleDbConnection(connectionString)
' Create and initialize the command object
Dim strSQL As String = "SELECT SizeID, ProductID, Sizes & ' - ' & Price AS Sizes, Price " & _
"FROM Sizes " & _
"WHERE (ProductID = " & productid & ")"
Dim objCmd As New OleDbCommand(strSQL, connection)
Dim objDR As OleDbDataReader
Try
connection.Open()
objCmd.ExecuteReader(CommandBehavior.CloseConnecti on)
Catch e As Exception
connection.Close()
Throw e
End Try
Dim myDDL As DropDownList = list.FindControl("ddlSizes")
myDDL.DataSource = objCmd
myDDL.DataTextField = "Sizes"
myDDL.DataValueField = "SizeID"
myDDL.DataBind()
End Sub