locked
How to write another value if it is 0 while writing the value from eval from database? RRS feed

  • Question

  • User56376785 posted

    I combine 3 tables into one repeater component and do databind operation. There are 5 fields in the repater where I write data with the Eval () function. one of them is asp: Image object .my pictures database is designed in this way. img1, img2, img3, img4 ...  If the picture is left blank or deleted, for example, the first picture on the saved page, I save it to the database as zero. With the eval function, for example, I want to set the value from the first image in the database to asp: image object. If the first value is registered as zero, I would like to show a picture that I have determined previously instead of this value.

    Wednesday, March 25, 2020 3:34 PM

All replies

  • User409696431 posted

    Assuming the value in your database is a string, even if it is 0, that "imagefile" is the name of your database field with a full path to the image, and that "defaultimage.jpg" is the full path to the default image when the "imagefile" value is "0".  Adjust to your actual names and values.

    <asp:Image ID="image1" runat="server" ImageUrl='<%# (string)Eval("imagefile")=="0"? "defaultimage.jpg" : Eval("imagefile") %>' ></asp:Image>
    
    
    
    
    Wednesday, March 25, 2020 4:04 PM