I want to display my database image into new tab when user click on the image.
I can do it with with static images because that time I have their static image url.
But I do not have any idea about how to do it with dynamic images.
Please help. A warm thanks in advance😁
This is my C# code – File1.aspx
:
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<div class="independence">
<figure class="column">
<asp:ImageButton CssClass="inimg" ID="Image1" OnClick="Image1_Click" runat="server" ImageUrl='<%# Eval("Picture","Admin/AdminGallery/Events/{0}") %>' />
</figure>
</div>
</ItemTemplate>
</asp:ListView>
File1.cs
:
protected void Image1_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect();
}
2
Answers
try this then.
You can do it this way:
First, the markup for the ListView:
And code behind to load up the ListView data:
And the result is now this:
And the target page ViewFighter.aspx has this markup:
And code behind assumes a URL with ID having been passed.
So, code behind for this target page is:
So, you don’t have to actually write a JavaScript function, but the image button does require what amounts to code as an JavaScript expression. That JavaScript code opens a new tab, and redirects the page to open ViewFighter.aspx in a new tab.
Above assumes an image path is stored in the database. However, the above approach would also work fine if the actual image was stored in the database column as opposed to an image path.
If you are storing a raw binary image in the database column, then I can add a few lines of code to above that demonstrates how the image could come from the database, and not using a path. (just ask in the comments, and I post additional code).
In above, I used 2 global helper routines that returns a data table from given SQL text, or SQL passed with a SqlCommand object.
Those 2 routines are: