Radgrid Bind Image to control error RRS feed

  • Question

  • Hi,

    I am using the following code to bind image from the database to my asp:Image control in the RadGrid Mastertable. However I am getting a null reference exceptionon the line "   iP.ImageUrl = "~/StreamImage.ashx?Id=" + user;" and I am not able to understand why is it giving me that
    Here is the code:

    <asp:Image ID="iPhoto1" runat="server" AlternateText="Profile Picture"    
         protected void btnSearch_Click(object sender, EventArgs e)
         var data = ss.qStudSearch(Common.GetValue(txtName.Text), 
                Common.GetValue(txtResearch.Text), currUser.iProgramID);
                rgSearch.DataSource = data;
                foreach (GridDataItem d in rgSearch.MasterTableView.Items)
                        int user = Convert.ToInt32(d.GetDataKeyValue("upid"));
                        var pix = ss.GetPics(user);
                        Image iP = 
                    if (pix != null)
                        iP.ImageUrl = "~/StreamImage.ashx?Id=" + user;
                        iP.ImageUrl = "~/images/no_image.jpg";
       }                           }

    The getpics method retrieves the images from the database and it is retrieving it properly as I checked it by debugging. However I am not able to assign it to the asp:Image control.. Can someone help me with this?
    • Moved by CoolDadTx Wednesday, February 21, 2018 3:46 PM ASP.NET related
    Thursday, February 15, 2018 11:40 PM

All replies

  • Hi hims16s,

    Thank you for posting here.

    According to your question is more related to ASP.NET, you could post a new thread in ASP.NET forum for suitable support.

    The Visual C# forum discuss and ask questions about the C# programming language, IDE, libraries, samples, and tools.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 21, 2018 2:36 AM