what is this error ?
Cannot apply indexing with [] to an expression of type 'System.Web.UI.WebControls.Image'
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Safeer Safeer171 reputationPosted Aug 25, 2013, 9:55 PM EDT
{
if(fuschool.HasFile)
{
string filename=Path.GetFileName(fuschool.PostedFile.FileName);
string strextension = Path.GetExtension(fuschool.FileName).ToLower();
if (strextension == ".jpg" || strextension == ".jpeg" || strextension == ".gif" || strextension == ".bmp" || strextension == ".jpe")
{
string photoname = "photoName" + DateTime.Now.Ticks + filename;
fuschool.SaveAs(Server.MapPath("~\\Gallery\\temprory\\" + photoname));
imgschool.Width=150;
imgschool.Height=150;
imgschool["photo"] = photoname;
}
}
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 25, 2013, 9:55 PM EDT
Please provide more details. If possible share the code.
Regards,
Iftikar
Safeer Safeer171 reputationPosted Aug 25, 2013, 10:00 PM EDT
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace ERP
{
class photosp : dbconnection
{
public int PhotoAdd(photoinfo infophoto)
{
try
{
if (sqlcon.State == ConnectionState.Closed)
sqlcon.Open();
SqlCommand sqlcmd = new SqlCommand("PhotoAdd", sqlcon);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.Add("@photoName", SqlDbType.VarChar).Value = infophoto.photoName;
sqlcmd.Parameters.Add("@photo", SqlDbType.VarChar).Value = infophoto.photo;
int a = sqlcmd.ExecuteNonQuery();
return a;
}
catch (Exception)
{
throw;
}
finally
{
sqlcon.Close();
}
}
public int PhotoEdit(photoinfo infophoto)
{
try
{
if (sqlcon.State == ConnectionState.Closed)
sqlcon.Open();
SqlCommand sqlcmd = new SqlCommand("PhotoEdit", sqlcon);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.Add("@photoId", SqlDbType.Decimal).Value = infophoto.photoId;
sqlcmd.Parameters.Add("@photoName", SqlDbType.VarChar).Value = infophoto.photoName;
sqlcmd.Parameters.Add("@photo", SqlDbType.VarChar).Value = infophoto.photo;
int a = sqlcmd.ExecuteNonQuery();
return a;
}
catch (Exception)
{
throw;
}
finally
{
sqlcon.Close();
}
}
public DataTable PhotoViewall()
{
DataTable dt = new DataTable();
try
{
if (sqlcon.State == ConnectionState.Closed)
sqlcon.Open();
SqlDataAdapter sqlda = new SqlDataAdapter("PhotoViewall", sqlcon);
sqlda.SelectCommand.CommandType = CommandType.StoredProcedure;
sqlda.Fill(dt);
}
catch (Exception)
{
throw;
}
finally
{
sqlcon.Close();
}
return dt;
}
public DataTable PhotoViewall(int index)
{
DataTable dt = new DataTable();
try
{
if (sqlcon.State == ConnectionState.Closed)
sqlcon.Open();
SqlDataAdapter sqlda = new SqlDataAdapter("PhotoViewall", sqlcon);
sqlda.SelectCommand.CommandType = CommandType.StoredProcedure;
sqlda.Fill(index, 4, dt);
}
catch (Exception)
{
throw;
}
finally
{
sqlcon.Close();
}
return dt;
}
public photoinfo PhotoView(decimal pid)
{
SqlDataReader sqldr = null;
photoinfo infophoto = new photoinfo();
try
{
if (sqlcon.State == ConnectionState.Closed)
sqlcon.Open();
SqlCommand sqlcmd = new SqlCommand("PhotoView", sqlcon);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.Add("@photoId", SqlDbType.Decimal).Value = pid;
sqldr = sqlcmd.ExecuteReader();
while (sqldr.Read())
{
infophoto.photo = sqldr["photo"].ToString();
infophoto.photoName = sqldr["photoName"].ToString();
}
}
catch (Exception)
{
throw;
}
finally
{
sqldr.Close();
sqlcon.Close();
}
return infophoto;
}
public int PhotoCount()
{
try
{
if (sqlcon.State == ConnectionState.Closed)
sqlcon.Open();
SqlCommand sqlcmd = new SqlCommand("PhotoCount", sqlcon);
sqlcmd.CommandType = CommandType.StoredProcedure;
int a = int.Parse(sqlcmd.ExecuteScalar().ToString());
return a;
}
catch (Exception)
{
throw;
}
finally
{
sqlcon.Close();
}
}
}
}
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 25, 2013, 10:03 PM EDT
imgschool.ImageUrl = "~\\Gallery\\temprory\\" + photoname;
Regards,
Iftikar