Image Display in gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tuman
    New Member
    • Feb 2008
    • 1

    Image Display in gridview

    I am making a project which is related to classified web site.
    I have used a gridview control. In which put some sqltable data.
    And i want to show a image which is store in my project folder,
    Whenever grid will display with my sqltabel data + image.
    I have created specific folder for every user who send the data.

    <div>
    <table style="vertical-align:middle; height:100%; width:100%">
    <tr>
    </tr>
    <tr>
    <td>
    &nbsp;</td>
    </tr>
    <tr>
    <td>
    <asp:GridView ID="grdImageVie wer" runat="server" AllowPaging="Tr ue" AutoGenerateCol umns="false"
    AutoGenerateEdi tButton="false" CellPadding="4" OnPageIndexChan ging ="Page_Load" >
    <Columns>
    <asp:HyperLinkF ield DataNavigateUrl Fields="Title" DataNavigateUrl FormatString="~/Resume/ResumeDetail.as px?Title={0}"
    DataTextField=" Title" HeaderText="Tit le" />


    <asp:BoundFie ld DataField="Desc ription" HeaderText="Des cription" />
    <asp:BoundFie ld DataField="Emai l" HeaderText="Ema il" />
    <asp:TemplateFi eld HeaderText="Ima ge">
    <ItemTemplate >
    <img alt="Image" src='<%#Eval("g rdImage")%>' />
    </ItemTemplate>
    </asp:TemplateFie ld>
    </Columns>
    </asp:GridView>
    </td>
    </tr>
    </table>

    </div>

    cs. file

    public partial class Resume_View : System.Web.UI.P age
    {
    protected void Page_Load(objec t sender, EventArgs e)
    {
    if (!IsPostBack)
    bindData();
    //BindDataImage() ;

    }

    private void bindData()
    {
    string query = "select Title,Descripti on,Email,ImageP ath from ResumePosting";
    DataTable table = DBUser.ExecuteQ uery(query);

    if (table.Rows.Cou nt == 0)
    return;

    int index = 0;

    DataTable dt = new DataTable();

    dt.Columns.Add( "Title", typeof(string)) ;
    dt.Columns.Add( "Descriptio n", typeof(string)) ;
    dt.Columns.Add( "Email", typeof(string)) ;
    dt.Columns.Add( "grdImage", typeof(string)) ;
    DataRow dr;
    int imageindex;
    string [] file = Directory.GetFi les(Server.MapP ath("~/Resume/Veeru/") + "\\", "*.jpg");
    int imagecount = file.Length;
    for (index = 0,imageindex=0; index < table.Rows.Coun t; index++,imagein dex++)
    {
    dr = dt.NewRow();
    dr[0] = table.Rows[index]["Title"].ToString();
    dr[1] = table.Rows[index]["Descriptio n"].ToString();
    dr[2] = table.Rows[index]["Email"].ToString();
    dr[3] = ResolveUrl("Thu mbnailCreator.a spx?ImageId=" + file[imageindex]);
    dt.Rows.Add(dr) ;
    if (imageindex == imagecount-1)
    {
    imageindex = -1;
    }
    }
    grdImageViewer. DataSource = dt;
    grdImageViewer. DataBind();
    }

    I want to show image related to row which is store in my project forlder.
  • lotus18
    Contributor
    • Nov 2007
    • 865

    #2
    I think this should be posted to a proper forum : )

    Comment

    Working...