ASP.NET: databind dropdownlist in template column
Hi, i am trying unsuccessfully to include a databound dropdownlist in the footer template of a datagrid template column. I get the error:
Object reference not set to an instance of an object. on teh line where i try and specify the datasource of the ddl. The code is below:
FROM THE WEB PAGE
<%# databinder.eval(container, "DataItem.Department") %>
<aspropDownList id="ddlDept" runat="server" DataTextField="dep_name" DataValueField="dep_id" />
FROM THE CODE BEHIND
Private Sub displayDeptReps()
dgDeptReps.DataSource = getDeptRepData()
Dim oDataFunc As New dataFunctions
Dim dtDepartments As DataTable
dtDepartments = (oDataFunc.noParameterQuery("stp_getDepartments")) 'returns a datatable containing the values for the ddl.
ddlDept.DataSource = New DataView(dtDepartments) 'I have also tried using the datatable as the source directly
ddlDept.DataTextField = "dep_name"
ddlDept.DataValueField = "dep_id"
This works so long as the ddl is outside of the datagrid!
Could anyone point me in the right direction? It appears that the ddl is not created yet, perhaps...
Solved it, for those who are interested, the solution is outlined in this article:
You don't declare a footer template in the template column, then you create a dropdownlist object, databind it and then add it to the footer cell during the itemcreated event of the datagrid.
Hope this stops someone else getting a headache.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)