The error appeared after i fixed another error in another Page
Here is the Code
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Webshop3.Models;
namespace Webshop3.Pages.Management
{
public partial class ManageProducts : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetImages();
if (!String.IsNullOrWhiteSpace(Request.QueryString["id"]))
{
int id = Convert.ToInt32(Request.QueryString["id"]);
FillPage(id);
}
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
ProductModel productModel = new ProductModel();
Product product = CreateProduct();
//testojme nese url ka parameter id
if (!String.IsNullOrWhiteSpace(Request.QueryString["id"]))
{
// ID existon -> update rreshtin ekzistes
int id = Convert.ToInt32(Request.QueryString["id"]);
lblResult.Text = productModel.UpdateProduct(id, product);
}
else
{
// nese nuk ekziston ID , krijo rresht te ri
lblResult.Text = productModel.InsertProduct(product);
}
}
private void FillPage(int id)
{
//Marim produktin e selektuar nga databaza
ProductModel productModel = new ProductModel();
var product = productModel.GetProduct(id);
//Mbushim textboxat
txtDescription.Text = product.Description;
txtName.Text = product.Name;
txtPrice.Text = product.Price.ToString();
ddlImage.SelectedValue = product.Image;
ddlType.SelectedValue = product.TypeId.ToString();
}
private void GetImages()
{
try
{
// Marim Images te Dropdown
string[] images = Directory.GetFiles(Server.MapPath("~/Images/Products/"));
// Vendoj FileName ne arraylist
ArrayList imageList = new ArrayList();
foreach (string image in images)
{
string imageName = image.Substring(image.LastIndexOf(@"\", StringComparison.Ordinal) + 1);
imageList.Add(imageName);
}
ddlImage.DataSource = imageList;
ddlImage.AppendDataBoundItems = true;
ddlImage.DataBind();
}
catch (Exception e)
{
lblResult.Text = e.ToString();
}
}
private Product CreateProduct()
{
Product product = new Product();
product.Name = txtName.Text;
product.Price = Convert.ToInt32(txtPrice.Text);
product.TypeId = Convert.ToInt32(ddlType.SelectedValue);
product.Description = txtDescription.Text;
product.Image = ddlImage.SelectedValue;
return product;
}
}
}
I was following a tutorial on youtube and i did the exact same thing as him , everything worked well until i arrived at this moment
Aucun commentaire:
Enregistrer un commentaire