Null reference in Item

S

Sam

Hi All,

I'm having troubles with populating data to the dropdownlist in a datagrid
and I just don't know what causes it. I have been struggling for 2 days now
Would some one give me a hand?

Here is what I have in the ItemDataBound

Dim ddlProduct As DropDownList =
CType(e.Item.Cells(1).FindControl("ddlFinalOffer"),
System.Web.UI.WebControls.DropDownList)

Dim ds1 As DataSet

ds1 = CreateDataSet()

ddlProduct .DataTextField = "ProductDesc"

ddlProduct.DataValueField = "ProductID"

ddlProduct .DataSource = ds1.Tables(0)

ddlProduct.DataBind()





some how I keep having null reference error and when I debug it, the
ddlProduct variable shows "nothing" when I hover my mouse on this variable.
It breaks when I tried to assign datafield to it. The code above shows ok
if I put in the "edit" event handler of the datagrid but the data does not
get populated in the dropdownlist.

Regards,

Sam
 
G

Guest

I think you need to use this check

if ( e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem )
{
//bind data
}

Note : code is in C#.
 
S

Sam

Avnrao,

Other thing I notice that the data seems to bind to the dropdownlist when I
click on the edit link of the datagrid row. Do you have any idea what might
cause it?

Sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top