TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Aktham Mahmoud
NA
720
37.5k
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:
<
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))
{
//Open Connection with D.B
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();
//DV_StafdUpade.DataBind();
lb_Info.Text =
"Employee image has been updated Successfully."
;
lb_Info.ForeColor = System.Drawing.Color.Green;
lb_Info.BorderColor = System.Drawing.Color.Green;
}
//End Using
}
//End Main If (file upload) has file
}
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
Reply
Answers (
2
)
asp.net core razor pages - cascade dropdownlists
Select Specific Column in Gridview Template Field using Loop in C#