DropDownList in datagrid

Posts   
 
    
MikeM
User
Posts: 7
Joined: 08-Dec-2004
# Posted on: 30-Dec-2004 10:57:11   

Hi,

I'm having a problem populating a dropdownlist in a datagrid.

The example code I've found on the web use datasets to populate the dropdownlist, however I'm using a collection as below, I've also tried a datatable with the same result:


                                    <asp:TemplateColumn>
                                        <EditItemTemplate>
                                        <asp:DropDownList ID="ProdDDL" Runat=server DataTextField="Prod_Desc" OnSelectedIndexChanged="GetProdTaskData">
                                        </asp:DropDownList>
                                        </EditItemTemplate>
                                    </asp:TemplateColumn>


        Dim _PRCol As New FGFM.CollectionClasses.PRODUCTDATACollection

        filterPR.Add(PredicateFactory.CompareValue(FGFM.PRODUCTDATAFieldIndex.INCLUDE_GFM, ComparisonOperator.Equal, "Y"))
        'daoPR.GetMultiAsDataTable(fieldsPR, dtlPR, 0, sorterPR, filterPR, Nothing, True, Nothing, Nothing, 0, 0)
        _PRCol.GetMulti(filterPR)
        Dim cnt As Integer
        ' just to check that I'm getting the correct data
        cnt = _PRCol.Count()
        'PopulateProdList
        ProdDDL.DataSource = _PRCol
        ProdDDL.DataTextField = "Prod_Desc"
        ProdDDL.DataValueField = "Prod_Desc"
        ProdDDL.DataBind()


When I run it I get an exception System.NullReferenceException: Object reference not set to an instance of an object

Any help would be appreciated

Mike

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 30-Dec-2004 11:26:57   

is there any stack trace given?

Frans Bouma | Lead developer LLBLGen Pro
MikeM
User
Posts: 7
Joined: 08-Dec-2004
# Posted on: 30-Dec-2004 11:33:51   

The stack trace is:


Source Error: 


Line 459:       cnt = _PRCol.Count()
Line 460:       'PopulateProdList
Line 461:       ProdDDL.DataSource = _PRCol
Line 462:       ProdDDL.DataTextField = "Prod_Desc"
Line 463:       ProdDDL.DataValueField = "Prod_Desc"


Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.]
   GFM.Task_new_work.PopulateProd() in C:\GFM\gfm\Task_new_work.aspx.vb:461
   GFM.Task_new_work.GetOrderTypes(Object sender, EventArgs e) in C:\GFM\gfm\Task_new_work.aspx.vb:419
   System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e) +108
   System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +26
   System.Web.UI.Page.RaiseChangedEvents() +115
   System.Web.UI.Page.ProcessRequestMain() +1099

I've tried putting the dropdownlist outside the datagris and it works ok, it's just when it's inside the datagrid

Thanks

Mike

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 30-Dec-2004 12:24:42   

if the exception is at line 461, ProdDDL is null.

Frans Bouma | Lead developer LLBLGen Pro