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:
- <ItemTemplate>
- <asp:ImageButton ID="ImageButton1" runat="server" BorderColor="#CC0000" BorderStyle="Dashed" BorderWidth="1px" Height="130px" ImageUrl='<%# Eval("S_photo") %>' OnCommand="ImageButton1_Command" Width="130px" />
- <asp:FileUpload ID="FileUpload_EmpPhoto" runat="server" />
- <asp:Button ID="Button1" runat="server" CausesValidation="False" OnCommand="Button1_Command" Text="Update" />
- <asp:Label ID="Modal_Lb_Status" runat="server"></asp:Label>
- </ItemTemplate>
Code behind here:
- protected void Button1_Command(object sender, CommandEventArgs e)
- {
- Label lb_Info = (Label)DV_StafdUpade.FindControl("Modal_Lb_Status");
- FileUpload FEmpNewImg = (FileUpload)DV_StafdUpade.FindControl("FileUpload_EmpPhoto");
-
- if (FEmpNewImg.HasFile)
- {
- string fileName = FEmpNewImg.FileName;
- string exten = Path.GetExtension(fileName);
-
- FEmpNewImg.SaveAs(Server.MapPath("~/images/staff/" + Path.GetFileName(fileName)));
- string link = "~/images/staff/" + Path.GetFileName(fileName);
- using (SqlConnection sqlcon = new SqlConnection(Constr))
- {
-
-
- sqlcon.Open();
- string query = "UPDATE Staff SET [S_photo]= @S_photo WHERE (Staff.UserId = @UserId)";
- SqlCommand sqlcmd = new SqlCommand(query, sqlcon);
- sqlcmd.Parameters.AddWithValue("@S_photo", link);
- sqlcmd.ExecuteNonQuery();
- sqlcmd.Dispose();
- sqlcon.Close();
-
- lb_Info.Text = "Employee image has been updated Successfully.";
- lb_Info.ForeColor = System.Drawing.Color.Green;
- lb_Info.BorderColor = System.Drawing.Color.Green;
- }
- }
-
- }
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