dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: ASP.NET: databind dropdownlist in template column

  1. #1
    Join Date
    Feb 2004
    Posts
    13

    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
    <asp:TemplateColumn HeaderText="Representing">
    <ItemTemplate>
    <%# databinder.eval(container, "DataItem.Department") %>
    </ItemTemplate>
    <FooterTemplate>
    <aspropDownList 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

  2. #2
    Join Date
    Feb 2004
    Posts
    13
    Solved it, for those who are interested, the solution is outlined in this article:

    http://www.extremeexperts.com/Net/Ar...stoFooter.aspx

    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.

    Matt

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles