Skip to content

Dynamic ImageButton Under DataList redirecting to the Image in Folder

Saswat Routroy

Asked Jan 2, 2012, 12:02 AM EST1 answer
Share
LinkedInX
Friends, i have a problem and i wish to have some help........ I am creating a matrimony site. When a person is registering, a folder is created by his/her username folder, ex- say if a person is using Damu234 as username then a folder will be created with path "~/Candidate_Pics/Male/Damu234" where Damu234 is a male candidate...if a female candidate is registering, with username Supriti36 then a folder with path "~/Candidate_Pics/Female/Supriti36" will be created.....

Now am using Session["Sex"], when Session["Sex"]=="Male" then "~Candidate_Pics/" + Convert.ToString(Session["Sex"]) + "/" will be traversed....


i'm using one image and one hyperlink field under the DataList control, i want to use ImageButton in place of Image so that on clicking ImageButton, the definit picture from the folder will be shown,

and i want it to happen at runtime, since based on session["sex"] and username, the userfolder having the pics will be selected.....

here's my aspx design code:

Div
















and my aspx.cs code::

protected void Page_Load(object sender, EventArgs e)
{
      if(!IsPostBack)
         {
              BindDataList();
         }
}

protected void BindDataList()//shows the pics from the user folder
{
          string[] list = Directory.GetFiles(Server.MapPath("/Candidate_Pics/" + Convert.ToString(Session["Sex"]) + "/" + txt_u_name.Text + "/"));
          var aList = from fileName in Directory.GetFiles(Server.MapPath("/Candidate_Pics/" + Convert.ToString(Session["Sex"]) + "/" + txt_u_name.Text + "/"))
select string.Format("/Candidate_Pics/" + Convert.ToString(Session["Sex"]) + "/" + txt_u_name.Text + "/{0}",   Path.GetFileName(fileName));
           dtlist.DataSource = aList;
           dtlist.DataBind();
}


i'm not using any database regarding folder pics, is there a way so that i can replace the Image inside the DataList by a ImageButton, so that when i click the button, it opens the coressponding image in a new page, or rather in a lightbox.....also i want to use a delete button inside the Datalist along with the ImageButton, so that i can delete the corresponding image from the folder....Can this be done and without using the concept of database?? Any help is appreciated.....


1 Answer

Know the answer? Post it. Somebody with the same question will find it here.