• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 337
  • Last Modified:

find dropdownlist inside gridview and fill list

is this correct?    i am getting this error
Error=Object reference not set to an instance of an object., Timestamp=2/10/2011 3:33:46 PM

Dim itemWhse As New System.Web.UI.WebControls.DropDownList
            itemWhse = CType(e.Item.Cells(9).FindControl("lstWhse"), System.Web.UI.WebControls.DropDownList)
                    itemWhse.Items.Add(New ListItem("GA", "GA"))
                itemWhse.Items.Add(New ListItem("MO", "MO"))
                itemWhse.Items.Add(New ListItem("NY", "NY"))
                itemWhse.Items.Add(New ListItem("OR", "OR"))
                itemWhse.Items.Add(New ListItem("SALE", "SALE"))
                itemWhse.Items.Add(New ListItem("123", "123"))
  • 3
1 Solution
HainKurtSr. System AnalystCommented:
try DirectCast

itemWhse = DirectCast(e.Item.Cells(9).FindControl("lstWhse"), System.Web.UI.WebControls.DropDownList)

and make sure the control you are looking for inside that cell, remember index start with 0 (try 8 or 10)
HainKurtSr. System AnalystCommented:
also try

itemWhse = DirectCast(e.Item.FindControl("lstWhse"), System.Web.UI.WebControls.DropDownList)
WiggingAuthor Commented:
also if the item is supposed to show on edit
in which even should i add this code?

item created   or datagrid1EditCommand  or datagrid1ItemDataBound
HainKurtSr. System AnalystCommented:
DataGrid.EditCommand Event

Occurs when the Edit button is clicked for an item in the DataGrid control.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now