Image in GridView ASP - asp.net

I have a grid view in which in one column I want to display images. I have image URL stored in the database.I want the the gridview to dynamically bind the ImageField with the url from the database.

Try this.
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="ProductImage" runat="server" ImageUrl='<%# Eval("ProductImagePath") %>'/>
</ItemTemplate>
</asp:TemplateField>
Or this
<asp:ImageField HeaderText="Image" DataImageUrlField="ProductImagePath"/>

Related

Display an image from a link in an ASP.Net GridView

I've saw ways to display binary images in a gridView - using repeaters, for example. I'm curious - how would you display an image which is stored as a link (i.e: https://s-media-cache-ak0.pinimg.com/736x/ee/dc/cb/eedccb62388bb15b8ba6564372c71bac.jpg) in a database? Is there any efficient, simple way to do it if I put the dataset source into the gridview (not using an imageField)?
You can try below code to display image in GridView which stored as a link in database. I have used simple HTML img tag to display image.
<asp:GridView ID="gvImages" CssClass="Gridview" runat="server" AutoGenerateColumns="False"
HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="white">
<Columns>
<asp:BoundField HeaderText = "Image Name" DataField="ImageURL" />
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<img src='<%# Eval("ImageURL") %>' Height="150" Width="150" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

imagefield clickable in a gridview

i have this imagefield in a gridview
<asp:ImageField HeaderText="Image" DataImageUrlField="Image_Path" ControlStyle-Width="50" ControlStyle-Height="50"/>
the image_path is a column name from the database that retuns the image link
i need to make this field clickable so once i click on it i need to popup a form just like this field:
<asp:TemplateField HeaderText="View">
<ItemTemplate>
<asp:LinkButton ID="LinkButton3" CommandName="Select" onClick="popup_click" class="table-actions-button ic-table-edit" runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
i tried to put an image button instead of an image field but i'm always getting submit query instead of the image...
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" DataImageUrlFormatString="Image_Path" ControlStyle-Width="50" ControlStyle-Height="50"/>
</ItemTemplate>
does anyone know how can i fix this?

How to add files from different input controls into gridview

Below is my requirement. I will have two browse buttons on the page , and two upload buttons on the page.
My requirement is to have both the attachments uploaded by the user to be displayed in a gridview in one row.
Upload1 and Upload2 are the two attachments uploaded by the user and i need to get them as below in the gridview.
Attachment 1 Attachment 2 Delete
Upload1 Upload2 Delete
Can you please help me with an easy way to achieve this?
If I understand you correctly you should be able to do this by using a TemplateField when you define your columns:
<Columns>
<asp:TemplateField HeaderText="FirstColumn">
<ItemTemplate>
<asp:FileUpload ID="fu_FirstFile" runat="server" /><br/>
<asp:Button ID="btn_UPloadFirst" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SecondCOlumn">
<ItemTemplate>
<asp:FileUpload ID="fu_SecondFile" runat="server" /><br/>
<asp:Button ID="btn_UPloadSecond" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>

loading gridview with hyperlink column

I have a gridview and added a column "Hyperlink" to all records by enabling autogeneratefields.
When this gridview is loaded and when I click the hyperlink across any record I want to redirect to some other page with entire record passed as query string to that page?
can anybody help me on this?
These links should clarify how to do it:
How to pass variables thru a DataGrid hyperlink column
How To: Use a HyperLink control inside a GridView
Sample code (Look at the NavigateUrl property of HyperLink):
<asp:GridView ID="urlGrid" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1"
runat="server"
NavigateUrl='<%# "RedirectPage.aspx?xxxx=" &
DataBinder.Eval(Container, "DataItem.xxxx") &
"&yyyy=" & DataBinder.Eval(Container, "DataItem.yyyy")%>'
Text="Go!">
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="SiteName" HeaderText="Site Name" />
</Columns>
</asp:GridView>

Gridview : Hyperlink and description in the same column cell

Apologies for the newbie question. My client wishes me to make a small change to the gridview on his http://www.flogitdonegal.com/SearchPage.aspx page.
Note the way the Title column is a hyperlink to view more information. This comes from a 'BriefDescription' field in the database.
How can I add 250 chars from the 'FullDescription' underneath the Title in the same cell, but I dont want it be a hyperlink.
Essentially it will be 2 fields coming into the same column.
Thanks in advance for all help.
John
If this is using a GridView you are most likely using a TemplateField as it is to display the HyperLink.
Within the ItemTemplate of the TemplateField you can specify an additional Label underneath using something as follows:
<asp:Label runat="server" id="FullDescLabel" Text='<%# DataBinder.Eval(Container.DataItem, "FullDescription") %>' />
You need to use the TemplateField and here is a tutorial that explains some of the other fields that GridView offers as well.
<asp:GridView ID="gvwCompounds" runat="server" DataSourceID="objItemsFromYourDB">
<Columns>
....
<asp:TemplateField>
<ItemTemplate HeaderText="Title">
<asp:HyperLink runat="server" ID="Hperlink1" NavigateUrl='<%# Eval("BriefDescriptionUrl") %>' Text='<%# Eval("BriefDescription") %>' />
<br />
<asp:Label runat="server" ID="Label1" Text='<%# Eval("FullDescription") %>' />
</ItemTemplate>
</asp:TemplateField>
....
</Columns>
</asp:GridView>

Resources