locked
GridView Event that gets activated after entry is complete RRS feed

  • Question

  • User1040894247 posted

    Dear all.

    There is a gridview on my aspx page. The gridview data are obtained from XMLDataSource.

    The third column of my gridview will contain image path. I will be using the path to display image on image-button.

    img = GridView1.SelectedRow.Cells[2].ToString();
    ImageButton1.ImageUrl = img;

    If I put the above codes on page-load event, I receive following error

    Object reference not set to an instance of an object. 

    Which means the gridview data haven't been loaded. What event can I use so that the codes can be run immediately after the data are loaded on the gridview.?

    Friday, October 7, 2016 1:21 PM

Answers

  • User347430248 posted

    Hi Saurav,

    if you are putting the code on load event and if your grid view is not loaded then you receive an error.

    so what you need to do is load the grid view before Load event.

    so that when your above mentioned code execute on load event then it get the data available in the grid view.

    (1) preinit (2) Init (3) initcomplete (4) PreLoad

    These 4 events called before load event.

    so you can use these events to load the grid view.

    you can view the Asp.Net page life cycle events mentioned in the link below. so that you can get detailed information regarding events.

    Life-Cycle Events

    Here I think you should try to use PreLoad Event.

    Regards

    Deepak

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 10, 2016 3:02 AM

All replies

  • User-471420332 posted

    Dear saurav,

                    Can you show your code. Or check below link will help.

    http://stackoverflow.com/questions/22869528/object-reference-not-set-to-an-instance-of-an-object-while-passing-data-from-gri

    Thank you

    Friday, October 7, 2016 2:13 PM
  • User347430248 posted

    Hi Saurav,

    if you are putting the code on load event and if your grid view is not loaded then you receive an error.

    so what you need to do is load the grid view before Load event.

    so that when your above mentioned code execute on load event then it get the data available in the grid view.

    (1) preinit (2) Init (3) initcomplete (4) PreLoad

    These 4 events called before load event.

    so you can use these events to load the grid view.

    you can view the Asp.Net page life cycle events mentioned in the link below. so that you can get detailed information regarding events.

    Life-Cycle Events

    Here I think you should try to use PreLoad Event.

    Regards

    Deepak

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 10, 2016 3:02 AM