Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more: , +
Hi Friends,
i want to create a user control to display my data from excel sheet and also read photo from a folder. Path of photos is in excel sheet. i am able to call data from excel sheet. but my user control does not work properly.My photos does not displayed and all data is on single line i am trying to arrange it but not succeed. please help me. code is here.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CircleSoftech.DAL;
using System.Data;
using System.IO;

public partial class Controls_ImageWithText : System.Web.UI.UserControl
{
    DBConn _Connector = new DBConn();
    DataTable ExcelTable = new DataTable();
    DataTable ResultDt = new DataTable();
    String[] ExcelSheet;
    String ExcelFileName = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        ExcelFileName = Server.MapPath("~/Teacher/TeacherDetails.xlsx");
        _Connector.RetriveExcelSheets(ref ExcelSheet, ExcelFileName);
        try
        {               
                  _Connector.FillDataTable(ref ExcelTable, ExcelFileName, ExcelSheet.GetValue(0).ToString());

                  
                  for (int i = 0; i <= ExcelTable.Rows.Count - 1; i++)
                  {
                      Image img = new Image();
                      img.ID = "Teacher" + i;
                      img.ImageUrl = (Server.MapPath("~/Teacher/" + ExcelTable.Rows[i][7].ToString()));
                      img.Width = Unit.Pixel(100);
                      img.Height = Unit.Pixel(120);

                      Label name = new Label();
                      name.ID = "name" + i;
                      name.Text = ExcelTable.Rows[i][1].ToString();

                      Label father = new Label();
                      father.ID = "father" + i;
                      father.Text = ExcelTable.Rows[i][2].ToString();

                      Label Dob = new Label();
                      Dob.ID = "dob" + i;
                      Dob.Text = ExcelTable.Rows[i][3].ToString();

                      Label Acadamic = new Label();
                      Acadamic.ID = "academic" + i;
                      Acadamic.Text = ExcelTable.Rows[i][4].ToString();

                      Label comercial = new Label();
                      comercial.ID = "comercial" + i;
                      comercial.Text = ExcelTable.Rows[i][5].ToString();

                      Label experience = new Label();
                      experience.ID = "experience" + i;
                      experience.Text = ExcelTable.Rows[i][6].ToString();

                     
                      this.Controls.Add(name);
                      this.Controls.Add(father);
                      this.Controls.Add(Dob);
                      this.Controls.Add(Acadamic);
                      this.Controls.Add(comercial);
                      this.Controls.Add(experience);
                      this.Controls.Add(img);
                  }
            }       

        catch { }
    }
}
Posted
Updated 6-Mar-13 19:43pm
v4
Comments
Orcun Iyigun 5-Mar-13 2:47am    
And why? what is the problem? My user control does not work properly is not sufficient!
Tiwari A K 5-Mar-13 3:02am    
my photo is not displayed and all data are in single line i am trying to arrange it properly but not succeed.
Orcun Iyigun 5-Mar-13 3:27am    
Still it is hard to diagnose your problem. Can you please provide some code. Also show the code block how you retrieve and display for the images. For data showing in single line have you added line breaks? Used "Environment.NewLine()" or "<br />" tag?
VishwaKL 6-Mar-13 5:31am    
Need more description for the problem,

1 solution

for image display remove Server.MapPath use only following code ..if image are present in ur website folder
img.ImageUrl ="~/Teacher/" + ExcelTable.Rows[i][7].ToString();

for new row simply add br tag next to label text..exampal
Label name = new Label();
name.ID = "name" + i;
name.Text = ExcelTable.Rows[i][1].ToString()+"</br>";

or u may add every time new label with text as br...for example
Label MyNewLine = new Label();
MyNewLine.Text = "<br/>";

hope it will help
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900