Solved

find dropdownlist inside gridview and fill list

Posted on 2011-02-10
4
320 Views
Last Modified: 2012-05-11
     
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"))
0
Comment
Question by:Wigging
  • 3
4 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 34866003
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)
0
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 34866009
also try

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

Author Comment

by:Wigging
ID: 34866072
also if the item is supposed to show on edit
in which even should i add this code?

item created   or datagrid1EditCommand  or datagrid1ItemDataBound
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 34866521
DataGrid.EditCommand Event

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

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.editcommand.aspx
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.NET 5 Templates 2 65
Help with Syntax 9 26
Need a starter for ETL protocol? 4 39
VB.net Facial recognition software (time and attendance) 6 16
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now