locked
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'PROFILEPHOTOS/ImageName'. RRS feed

  • Question

  • User-2074858223 posted

    Am trying to display image in folder PROFILEPHOTOS which i stored the ImageName in table and is showing this error

     <a class="" href='<%#getUserHREF1(Container.DataItem)%>' >
                                                                                    
                                             
    
                                    <img src='<%#Eval("PROFILEPHOTOS/ImageName")%>' class=" img-circle animated fadeInDown"
                                        style="border: 1px solid #E0E0E0; width:55px; height:55px;" />
                                               </a>
                                            

    Server Error in '/' Application.
    DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'PROFILEPHOTOS/ImageName'.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    
    Exception Details: System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'PROFILEPHOTOS/ImageName'.
    
    Source Error:
    
    
    Line 1803:                                     
    Line 1804:
    Line 1805:                                <img src='<%#Eval("PROFILEPHOTOS/ImageName")%>' class=" img-circle animated fadeInDown"
    Line 1806:                                    style="border: 1px solid #E0E0E0; width:55px; height:55px;" />
    Line 1807:                                           </a>
    
    
    Saturday, November 25, 2017 6:43 PM

Answers

  • User-1838255255 posted

    Hi micah2012,

    According to your description, I am not clear what data control you use? I use a gridview to show the image in the folder with ImageField, please check the following sample code:

    Sample Code:

    <asp:GridView ID="Gv_imgs" CssClass="grid" runat="server" AutoGenerateColumns="false" ShowHeader="false">
                    <Columns>
                        <asp:BoundField DataField="Text" HeaderText="Name" />
                        <asp:ImageField DataImageUrlField="Value" ControlStyle-Height="75" ControlStyle-Width="75" HeaderText="Images" />
                    </Columns>
    </asp:GridView>
    
    
     protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    string[] ImagePaths = Directory.GetFiles(Server.MapPath("~/Images/"));
                    List<ListItem> Imgs = new List<ListItem>();
                    foreach (string imgPath in ImagePaths)
                    {
                        string ImgName = Path.GetFileName(imgPath);
                        Imgs.Add(new ListItem(ImgName, "~/Images/" + ImgName));
                    }
                    Gv_imgs.DataSource = Imgs;
                    Gv_imgs.DataBind();
                }
            }

    Result:

    Best Regards,

    Eric Du

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 27, 2017 8:21 AM

All replies

  • User-1629691846 posted

    If you are getting image name at server side (.cs file), Then use asp.net server control for image and bind the image there at server side.

    <asp:Image ID="imgCtrlID" runat="server" Height="100px" Width="100px" />

    Then you can bind the image as :

    imgCtrlID.ImageUrl = "YourFolder\ImageName.Extension";

    Monday, November 27, 2017 6:49 AM
  • User-1838255255 posted

    Hi micah2012,

    According to your description, I am not clear what data control you use? I use a gridview to show the image in the folder with ImageField, please check the following sample code:

    Sample Code:

    <asp:GridView ID="Gv_imgs" CssClass="grid" runat="server" AutoGenerateColumns="false" ShowHeader="false">
                    <Columns>
                        <asp:BoundField DataField="Text" HeaderText="Name" />
                        <asp:ImageField DataImageUrlField="Value" ControlStyle-Height="75" ControlStyle-Width="75" HeaderText="Images" />
                    </Columns>
    </asp:GridView>
    
    
     protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    string[] ImagePaths = Directory.GetFiles(Server.MapPath("~/Images/"));
                    List<ListItem> Imgs = new List<ListItem>();
                    foreach (string imgPath in ImagePaths)
                    {
                        string ImgName = Path.GetFileName(imgPath);
                        Imgs.Add(new ListItem(ImgName, "~/Images/" + ImgName));
                    }
                    Gv_imgs.DataSource = Imgs;
                    Gv_imgs.DataBind();
                }
            }

    Result:

    Best Regards,

    Eric Du

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 27, 2017 8:21 AM