Null reference in Item

Discussion in 'ASP .Net' started by Sam, Jul 11, 2006.

  1. Sam

    Sam Guest

    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
     
    Sam, Jul 11, 2006
    #1
    1. Advertising

  2. 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#.

    "Sam" wrote:

    > 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
    >
    >
    >
     
    =?Utf-8?B?YXZucmFv?=, Jul 11, 2006
    #2
    1. Advertising

  3. Sam

    Sam Guest

    Hi Avnrao,

    It works like a charm. Thank you very much.

    Sam



    "avnrao" <> wrote in message
    news:...
    >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#.
    >
    > "Sam" wrote:
    >
    >> 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
    >>
    >>
    >>
     
    Sam, Jul 11, 2006
    #3
  4. Sam

    Sam Guest

    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



    "avnrao" <> wrote in message
    news:...
    >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#.
    >
    > "Sam" wrote:
    >
    >> 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
    >>
    >>
    >>
     
    Sam, Jul 12, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ssoss

    Display Related Item or Add Item

    ssoss, Sep 17, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    519
    ssoss
    Sep 19, 2003
  2. Kel Good
    Replies:
    2
    Views:
    13,295
    Kel Good
    Apr 25, 2004
  3. Replies:
    5
    Views:
    27,598
    Mike Schilling
    Mar 29, 2006
  4. Replies:
    2
    Views:
    642
  5. root

    item[LENGTH] vs. *item and malloc()

    root, Aug 21, 2003, in forum: C Programming
    Replies:
    2
    Views:
    399
    Eric Sosman
    Aug 21, 2003
Loading...

Share This Page