Neeraj Verma
Neeraj Verma

Reputation: 2334

DataImageUrlFormatString property Not working

I am working on old Asp .NET GridView Image Field

this is My Sample Code

 <asp:GridView>
<Columns> 
<asp:ImageField DataImageUrlField="Camera" DataImageUrlFormatString= "test.aspx?ImageID={0}" />
</Columns>
  </asp:GridView>

I got this code from one reference but DataImageUrlFormatString property is not working to redirect

On googling , I found value of Property like this

dataimageurlformatstring="~\Images\{0}.jpg"

...other code I found is used by itemtemplate

<asp:templatefield>
    <itemtemplate>
        <asp:image id="Image1" runat="server" imageurl='<%# String.Format("~/{0}/{1}", Eval("dirname"), Eval("filename")) %>' />
    </itemtemplate>
</asp:templatefield>

But I want to use asp:ImageField

How that property can be use to Page redirect .OR do I need to work with c# Code to redirect ?


Solved

this is working

            <asp:GridView ID="GridView1" Width="100%" runat="server" AutoGenerateColumns="false"
                Font-Names="Arial">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <a href="DiscriptionPurchase.aspx?ProductID=<%#Eval("Id")%>">
                                <asp:Image ID="Camera" Height="100" Width="100" runat="server" ImageUrl='<%#Eval("Camera")%>'  />
                            </a>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>

this is table

enter image description here

Upvotes: 0

Views: 517

Answers (1)

Naved Ansari
Naved Ansari

Reputation: 660

You may take the image in anchor tag and provide the redirect URL in anchor tag as mentioned below

            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <a href="test.aspx?ImageID=<%#Eval("ImageId")%>">
                            <asp:Image ID="Image1" runat="server" ImageUrl='ImageURL' /></a>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>

Upvotes: 1

Related Questions