Images inside GridView

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mil111
    New Member
    • Jan 2008
    • 9

    Images inside GridView

    Hi,

    can enybody help me please. I have a gridview with column that shows the images dynamically from database (see code below). What I need it to do is check to see if there is an image in each row to display it, and if there is not then display a standard image from directory. I think that is better solution than storing default images in each row in database where there is no image (users should be able to upload images). How can I do this?

    Thanks.

    <asp:datagrid id="myGrid" runat="server"
    width="92%" cellpadding="5" font-size="8pt"
    gridlines="hori zontal"
    headerstyle-backcolor="slat egray"
    headerstyle-forecolor="ivor y"
    headerstyle-font-bold="true"
    ItemStyle-VerticalAlign=" Top"
    AutoGenerateCol umns="false"
    CellSpacing="5" >

    <columns>
    <asp:templateco lumn>
    <itemtemplate >
    <a href='Home.aspx ' >
    <img alt="Click for details"
    src="Handler.as hx?Image_Id=<%# Eval("Image_Id" ) %>" />
    </a>
    </itemtemplate>
    </asp:templatecol umn>

    <asp:boundcolum n headertext="Ima ge_Id"
    datafield="Imag e_Id" />
    <asp:boundcolum n headertext="Ima ge_Type"
    datafield="Imag e_Type" />
    </columns>
    <ItemStyle VerticalAlign=" Top" />
    <HeaderStyle BackColor="Slat eGray" Font-Bold="True" ForeColor="Ivor y" />

    </asp:datagrid>
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    One method for doing this is put the default path in the table when no image is present for that record. So you do not need to check if Image exists or not in the .Net code.


    Originally posted by mil111
    Hi,

    can enybody help me please. I have a gridview with column that shows the images dynamically from database (see code below). What I need it to do is check to see if there is an image in each row to display it, and if there is not then display a standard image from directory. I think that is better solution than storing default images in each row in database where there is no image (users should be able to upload images). How can I do this?

    Thanks.

    <asp:datagrid id="myGrid" runat="server"
    width="92%" cellpadding="5" font-size="8pt"
    gridlines="hori zontal"
    headerstyle-backcolor="slat egray"
    headerstyle-forecolor="ivor y"
    headerstyle-font-bold="true"
    ItemStyle-VerticalAlign=" Top"
    AutoGenerateCol umns="false"
    CellSpacing="5" >

    <columns>
    <asp:templateco lumn>
    <itemtemplate >
    <a href='Home.aspx ' >
    <img alt="Click for details"
    src="Handler.as hx?Image_Id=<%# Eval("Image_Id" ) %>" />
    </a>
    </itemtemplate>
    </asp:templatecol umn>

    <asp:boundcolum n headertext="Ima ge_Id"
    datafield="Imag e_Id" />
    <asp:boundcolum n headertext="Ima ge_Type"
    datafield="Imag e_Type" />
    </columns>
    <ItemStyle VerticalAlign=" Top" />
    <HeaderStyle BackColor="Slat eGray" Font-Bold="True" ForeColor="Ivor y" />

    </asp:datagrid>

    Comment

    Working...