Solved

find dropdownlist inside gridview and fill list

Posted on 2011-02-10
4
319 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

20 Experts available now in Live!

Get 1:1 Help Now