locked
Image in datalist RRS feed

  • Question

  • User66371569 posted

    <img id="image1" class="imgg" onclick = "LoadDiv(this.src, this)" src = "<%# Eval("attach")%>" width ="200" height = "150" alt="<%# Eval("imagename")%>" style ="cursor:pointer; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); border-radius:8px; margin-right:10px " />

    I have this image inside datalist  what I want to hide it    

    I used   

    Protected Sub Item_DataBound(sender As Object, e As DataListItemEventArgs) Handles DataList1.ItemDataBound

    Dim Imge = DirectCast(e.Item.FindControl("image1"), System.Web.UI.WebControls.Image)

    img.visible=false

    end sub

    but always error appears

    Object reference not set to an instance of an object.

    please help

    Saturday, October 20, 2018 7:32 AM

Answers

  • User-369506445 posted

    hi

    in <g class="gr_ gr_13 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" id="13" data-gr-id="13">you</g> data list you use <g class="gr_ gr_34 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="34" data-gr-id="34">a Img</g> tag that is <g class="gr_ gr_186 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="186" data-gr-id="186">a Html</g> Image control  but in your Item_DataBound you are casting to <g class="gr_ gr_134 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="134" data-gr-id="134">a Image</g> control

    please change your Datalist

    <img id="image1" class="imgg" onclick = "LoadDiv(this.src, this)" src = "<%# Eval("attach")%>" width ="200" height = "150" alt="<%# Eval("imagename")%>" style ="cursor:pointer; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); border-radius:8px; margin-right:10px " />

    to

                    <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("attach") %>' AlternateText='<%# Eval("imagename") %>'
                        CssClass="imgg" Width="200" Height="150"
                        Style="cursor: pointer; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); border-radius: 8px; margin-right: 10px" />
    
            

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 20, 2018 10:02 AM

All replies

  • User-369506445 posted

    hi

    in <g class="gr_ gr_13 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" id="13" data-gr-id="13">you</g> data list you use <g class="gr_ gr_34 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="34" data-gr-id="34">a Img</g> tag that is <g class="gr_ gr_186 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="186" data-gr-id="186">a Html</g> Image control  but in your Item_DataBound you are casting to <g class="gr_ gr_134 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="134" data-gr-id="134">a Image</g> control

    please change your Datalist

    <img id="image1" class="imgg" onclick = "LoadDiv(this.src, this)" src = "<%# Eval("attach")%>" width ="200" height = "150" alt="<%# Eval("imagename")%>" style ="cursor:pointer; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); border-radius:8px; margin-right:10px " />

    to

                    <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("attach") %>' AlternateText='<%# Eval("imagename") %>'
                        CssClass="imgg" Width="200" Height="150"
                        Style="cursor: pointer; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); border-radius: 8px; margin-right: 10px" />
    
            

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 20, 2018 10:02 AM
  • User66371569 posted

    I had to add   runat="server"

    then in code I used this line to get my image1

    Dim imgg = DirectCast(e.Item.FindControl("image1"), System.Web.UI.HtmlControls.HtmlImage)

    imgg.visible=False

    thank you

    Saturday, October 20, 2018 1:28 PM