My GridView Markup:
<asp:GridView ID="GrdVw" visible="False" runat="server" AllowPaging="True"
AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title" />
<asp:BoundField DataFi
eld="Comment" HeaderText="Comment" />
<asp:TemplateField HeaderText="Review Document">
<ItemTemplate>
<asp:Image ID="currentDocFile" runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:FileUpload ID="reviewDoc_UpldFl" runat="server" />
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
My Bind Method that I call from Page_Load and after Cancelling/Updating, etc:
private void BindGrdVw()
{
List<ArticleComments> commentsList = ArticleCommentsBLL.GetComments(ArticleID);
if (cruiseReviewsList.Count != 0)
{
GrdVw.DataSource = commentsList;
GrdVw.DataKeyNames = new string[] { "ID" };
GrdVw.DataBind();
GrdVw.Visible = true;
}
}
..Now as you see I have a template field, I access the ‘FileUpload’ control in the EditTemplate by ‘FindControl()’ of the row that I’m editing. but how can I access the ‘Image’ control’s property ‘ImageUrl’.
I need to set it to something like the following, this is a sample code from another project in the code behind file but I was able to access the image directly.
currentProfilePic_Img.ImageUrl = ConfigurationManager.AppSettings["cruisesPpUploadPath"].ToString() + currentCruise.ProfilePic;
*The AppSettings returns the path for the folder that I use for uploading.
*currentCruise is an object and it’s properties was assigned through my DAL layer.
I think I understand what you’re trying to do…
If you want to bind the image control URL dynamically, you will have to hook into the RowDataBound event of the GridView.
Hope this helps!
More info here:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onrowdatabound.aspx