Hello Everyone.
i need your help.
i want to use fileupload control in gridview. so when user wants to update their record along with image too(no problem in other field. but i want to update image too);
i used template edit template filed for using fileupload control.
but how to update its making confusion. so can anyone help me.
i m not using sqldata sources. (using my database.mdf)
for this if code is needed i can send it.
Thanks
Loading
Rashid KhanPosted Apr 3, 2010, 7:36 AM
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
SqlParameter[] param = new SqlParameter[6];
param[0] = new SqlParameter("@EmpId", SqlDbType.Int);
string code = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
param[0].Value = Convert.ToInt32(code);
param[1]= new SqlParameter("@Ename",SqlDbType.NChar,20);
param[1].Value=((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
param[2] = new SqlParameter("@Salary", SqlDbType.Float);
param[2].Value = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
param[3] = new SqlParameter("@Status", SqlDbType.Bit);
param[3].Value = ((CheckBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Checked;
param[4]=new SqlParameter("@Address",SqlDbType.NChar,100);
param[4].Value=((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text;
param[5] = new SqlParameter("@Img", SqlDbType.NChar, 100);
FileUpload FileUpload1 =(FileUpload)GridView1.Rows[e.RowIndex].FindControl("FileUpload1");
if (FileUpload1.HasFile)
{
if (CheckExtension(FileUpload1.FileName))
{
string path = "~//EmpImages";
path = path + "//" + FileUpload1.FileName;
FileUpload1.SaveAs(Server.MapPath(path));
}
}
param[5].Value = FileUpload1.FileName;
if(objEMS.ExecuteQuery(objEMS.Connect(),"usp_UpdateEmployee",param)>0)
{
GridView1.EditIndex=-1;
BindGrid();
}
}
#endregion
#region
protected Boolean CheckExtension(string FileName)
{
string Extension = Path.GetExtension(FileName).ToLower();
switch (Extension)
{
case ".gif": return true;
case ".png": return true;
case ".jpg": return true;
case ".jpeg": return true;
case ".bitmap": return true;
default: return false;
}
}
#endregion
Vijay KumarPosted Apr 3, 2010, 7:13 AM
Can u send that code to Me..
Rashid KhanPosted Apr 3, 2010, 7:08 AM
i got the concept.
if anyone who is also facing this problem, tell me, i can send the code .
Thanks