wrote:
> I searched for this and found an answer, but it did not help. In my
> GridView there is a fileupload and a button click event to save the
> file upload. I am naming the file uploaded after the primary key field
> of my table, so, if I have employeeid 4, then my file name is 4.jpg.
>
> What I cannot do is reference that current employeeid. If click edit,
> my edittemplate show and my fileupload and button are visible. In that
> buttons event, I need the employee id of that row.
>
> I'm not sure how to get that.
>
> Thank you for any help.
After much searching here is what I did:
if (e.CommandName == "addImage")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row =
(GridViewRow)((Control)e.CommandSource).Parent.Par ent;
FileUpload fileUpload = (FileUpload)
GridView1.Rows[row.RowIndex].FindControl("FileUpload1");
if (fileUpload.HasFile)
{
fileUpload.SaveAs(Server.MapPath(".\\images\\") +
e.CommandArgument + ".jpg");//get employeeid
}
else
{
Response.Write("No File Uploaded.");
}
}
Where e.CommandArgument is assigned when the control is built by
CommandArgument='<%# Eval("employeeid")%>'
The commandargument holds the data for my file and the commandsource
parent(s) hold the row value so that I know what row clicked the upload
button.