Aktham Mahmoud

Aktham Mahmoud

  • NA
  • 720
  • 35.1k

Why I cann't update one column by details View Control.

Dec 20 2020 11:06 AM
Greeting
I designed a senario to update employee information [salary, position, photo and etc].
a normal scinario when I select user open details view and get all colums and a user updated what is required to update.
But I make new scinario : Just open details view in [Read only mode] to update image only if that required and if required more details click on edit button and then change [details view] from [Read only mode] to [edit mode].
 
a problem is an update button code an want to update employee imagem see a code below:
 
  1. <ItemTemplate>           
  2.     <asp:ImageButton ID="ImageButton1" runat="server" BorderColor="#CC0000" BorderStyle="Dashed" BorderWidth="1px" Height="130px" ImageUrl='<%# Eval("S_photo") %>' OnCommand="ImageButton1_Command" Width="130px" />  
  3.     <asp:FileUpload ID="FileUpload_EmpPhoto" runat="server" />  
  4.     <asp:Button ID="Button1" runat="server" CausesValidation="False" OnCommand="Button1_Command" Text="Update" />  
  5.     <asp:Label ID="Modal_Lb_Status" runat="server"></asp:Label>  
  6. </ItemTemplate>  
 Code behind here:
  1. protected void Button1_Command(object sender, CommandEventArgs e)  
  2.   {  
  3.       Label lb_Info = (Label)DV_StafdUpade.FindControl("Modal_Lb_Status");  
  4.       FileUpload FEmpNewImg = (FileUpload)DV_StafdUpade.FindControl("FileUpload_EmpPhoto");  
  5.        
  6.           if (FEmpNewImg.HasFile)  
  7.           {  
  8.               string fileName = FEmpNewImg.FileName;  
  9.               string exten = Path.GetExtension(fileName);  
  10.   
  11.               FEmpNewImg.SaveAs(Server.MapPath("~/images/staff/" + Path.GetFileName(fileName)));  
  12.               string link = "~/images/staff/" + Path.GetFileName(fileName);  
  13.               using (SqlConnection sqlcon = new SqlConnection(Constr))  
  14.               {  
  15.            
  16.               //Open Connection with D.B  
  17.               sqlcon.Open();  
  18.               string query = "UPDATE Staff SET [S_photo]= @S_photo WHERE (Staff.UserId = @UserId)";  
  19.               SqlCommand sqlcmd = new SqlCommand(query, sqlcon);  
  20.               sqlcmd.Parameters.AddWithValue("@S_photo", link);  
  21.               sqlcmd.ExecuteNonQuery();  
  22.               sqlcmd.Dispose();  
  23.               sqlcon.Close();  
  24.               //DV_StafdUpade.DataBind();  
  25.               lb_Info.Text = "Employee image has been updated Successfully.";  
  26.               lb_Info.ForeColor = System.Drawing.Color.Green;  
  27.               lb_Info.BorderColor = System.Drawing.Color.Green;  
  28.               }//End Using  
  29.           }//End Main If (file upload) has file   
  30.        
  31.   }  
So what do you think:
1) a problem I cann't update one column in [Read only mode] till if I desgined a command to update.
 
Thanks 
 
 
 
 

Answers (2)