Solved

find dropdownlist inside gridview and fill list

Posted on 2011-02-10
4
326 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 56

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 56

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 56

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

623 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