Ann K
asked on
Word Directory is not in the drop down list
Can you tell me why its not showing the word Directory in the drop down list?
ManageProductType.aspx.cs
using System;
using System.Collections.Generic ;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Pages_Management_ManagePro ducts : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
GetImages();
}
private void GetImages()
{
try
{
//Get all filepaths
string[] images = Directory.GetFiles(Server. MapPath("~ /Images/Pr oducts/")) ;
ArrayList imageList = new ArrayList();
foreach (string image in images)
{
string imageName = image.Substring(image.Last IndexOf(@" \", StringComparison.Ordinal) + 1);
imageList.Add(imageName);
}
// Set the arrayList as the dropdownview's datasource and refresh
ddlImage.DataSource = imageList;
ddlImage.AppendDataBoundIt ems = true;
ddlImage.DataBind();
}
catch(Exception e)
{
lblResult.Text = e.ToString();
}
}
private Product CreateProduct()
{
Product product = new Product();
product.Name = txtName.Text;
//product.Price = Convert.ToDouble(txtPrice. Text);
product.TypeId = Convert.ToInt32(ddlType.Se lectedValu e);
product.Description = txtDescription.Text;
product.Image = ddlImage.SelectedValue;
return product;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
ProductModel productModel = new ProductModel();
Product product = CreateProduct();
lblResult.Text = productModel.InsertProduct (product);
}
}
ManageProductType.aspx.cs
using System;
using System.Collections.Generic
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Pages_Management_ManagePro
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
GetImages();
}
private void GetImages()
{
try
{
//Get all filepaths
string[] images = Directory.GetFiles(Server.
ArrayList imageList = new ArrayList();
foreach (string image in images)
{
string imageName = image.Substring(image.Last
imageList.Add(imageName);
}
// Set the arrayList as the dropdownview's datasource and refresh
ddlImage.DataSource = imageList;
ddlImage.AppendDataBoundIt
ddlImage.DataBind();
}
catch(Exception e)
{
lblResult.Text = e.ToString();
}
}
private Product CreateProduct()
{
Product product = new Product();
product.Name = txtName.Text;
//product.Price = Convert.ToDouble(txtPrice.
product.TypeId = Convert.ToInt32(ddlType.Se
product.Description = txtDescription.Text;
product.Image = ddlImage.SelectedValue;
return product;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
ProductModel productModel = new ProductModel();
Product product = CreateProduct();
lblResult.Text = productModel.InsertProduct
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And for Directory, you need to import System.IO
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You.