Hello, I have a gridview that displays data from a database. The datbase stores the image filename (string) among other things for an item.
I have the fileupload control showing in the EDIT view, and that uploads the file just fine.
The problem is, I want to update the image filename in the database and I am not sure how to get the data to the textbox control that the gridview uses to UPDATE the database. The textbox control i have set the visibility to hidden. here is the aspx code:
<asp:TemplateField HeaderText="Image" SortExpression="Image">
<EditItemTemplate>
<asp:TextBox ID="txtImage" runat="server" Text='<%# Bind("Image") %>' Visible="False" OnTextChanged="txtImage_TextChanged"></asp:TextBox>
<asp:FileUpload ID="FileUpload1" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Width="50px" AlternateText='<%# Eval("Image") %>' ImageUrl='<%# "images/hardware/" + Eval("Image") %>' />
</ItemTemplate>
</asp:TemplateField>
And here is the function that stores the file onto the server, and places the filename into a variable:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
FileUpload fileUpload = row.Cells[0].FindControl("FileUpload1") as FileUpload;
if ( fileUpload != null && fileUpload.HasFile)
{
strFileName = fileUpload.FileName;
fileUpload.SaveAs(Server.MapPath("images/hardware/" + strFileName));
TextBox txtImage = row.Cells[0].FindControl("txtImage") as TextBox;
txtImage.Text = strFileName;
}
}
So where do I go from here? I think the update has occured already or something? Because the "txtImage.Text" does not update the database... Am I out of order here or something? I can manipulate values in the textbox in this function before it gets saved to the DB right? Thanks for your help on this one.