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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Iftikar HussainPosted Aug 26, 2013, 2:03 AM
imgschool.ImageUrl = "~\\Gallery\\temprory\\" + photoname;
Regards,
Iftikar
Safeer SafeerPosted Aug 26, 2013, 2:00 AM
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 HussainPosted Aug 26, 2013, 1:55 AM
Please provide more details. If possible share the code.
Regards,
Iftikar
Safeer SafeerPosted Aug 26, 2013, 1:55 AM
{
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;
}
}