Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET WebForms C#3.5 , +
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.
 
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 4-Mar-13 21:42pm
Edited 6-Mar-13 20:43pm
v4
Comments
Orcun Iyigun at 5-Mar-13 2:47am
   
And why? what is the problem? My user control does not work properly is not sufficient!
Tiwari A K at 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 at 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 at 6-Mar-13 5:31am
   
Need more description for the problem,

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v3

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

  Print Answers RSS
0 OriginalGriff 490
1 Maciej Los 299
2 BillWoodruff 174
3 /\jmot 170
4 Suraj Sahoo | Coding Passion 150
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 7 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100