mattisimo
05-13-2004, 11:34 AM
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
<asp:TemplateColumn HeaderText="Representing">
<ItemTemplate>
<%# databinder.eval(container, "DataItem.Department") %>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList id="ddlDept" runat="server" DataTextField="dep_name" DataValueField="dep_id" />
</FooterTemplate>
</asp:TemplateColumn>
FROM THE CODE BEHIND
Private Sub displayDeptReps()
dgDeptReps.DataSource = getDeptRepData()
dgDeptReps.DataBind()
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"
ddlDept.DataBind()
End Sub
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...
Thanks,
Matt
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
<asp:TemplateColumn HeaderText="Representing">
<ItemTemplate>
<%# databinder.eval(container, "DataItem.Department") %>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList id="ddlDept" runat="server" DataTextField="dep_name" DataValueField="dep_id" />
</FooterTemplate>
</asp:TemplateColumn>
FROM THE CODE BEHIND
Private Sub displayDeptReps()
dgDeptReps.DataSource = getDeptRepData()
dgDeptReps.DataBind()
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"
ddlDept.DataBind()
End Sub
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...
Thanks,
Matt