Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Ihave a grid view binded to xml datasource

The problem is that I want to made a TemplateField which has an imagebutton and i want to get the imagebutton.imageurl from XmlDataSource
Note that the gridview work well without the TemplateField
i have a folder called (img) Contains some images which i want to use it with my ImageButton
and i have a (xml node) called( r_image )and it Contains the names of the mentioned images

I have tried something like this:
ASP.NET
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
                   AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="XmlDataSource1"
                   Width="155px" style="margin-right: 0px" BorderColor="White"
                   BorderStyle="None" BorderWidth="0px" ForeColor="Black" ShowHeader="False"
                   PageSize="3">
                   <AlternatingRowStyle BorderStyle="None" />
                    <Columns>
                             <asp:TemplateField HeaderText="">
               <EditItemTemplate>
                   <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("r_imge") %>'></asp:TextBox>
               </EditItemTemplate>
               <ItemTemplate>

                   <asp:ImageButton ID="Image1" runat="server"
                     CommandName="select"   ImageUrl='<%# Eval("r_imge", "~/img/{0}") %>'   Width="150px" height="150px" />
           </ItemTemplate>
               <ControlStyle Height="150px" Width="150px" BorderStyle="None" />
               <ItemStyle Height="150px" Width="150px" />
           </asp:TemplateField>

                   </Columns>
                   <EditRowStyle BorderStyle="None" />
                   <EmptyDataRowStyle BorderStyle="None" />
                   <FooterStyle BackColor="White" BorderColor="Black" BorderStyle="None" />
                   <HeaderStyle BackColor="White" BorderColor="White" BorderStyle="None"
                       BorderWidth="0px" ForeColor="Black" />
                   <PagerSettings Mode="NumericFirstLast" />
                   <PagerStyle ForeColor="Black" />
                   <RowStyle BorderStyle="None" />
                   <SelectedRowStyle BorderStyle="None" />
               </asp:GridView>

   <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/press_r.xml"
                   TransformFile="~/press_r.xsl"></asp:XmlDataSource>


I think that the eval() didn`t work with xml but i don`t know any thing else
hope you can help me plz
thank you
Posted
Updated 4-Feb-12 10:03am
v2
Comments
Christian Graus 4-Feb-12 14:33pm    
Why is your question marked XML, and not ASP.NET ?
Martin Arapovic 4-Feb-12 16:41pm    
I noticed, that in question you said that you have "r_image" in xml, but in your markup code you have "r_imge"...
Maybe that's the mistake, but I think that you should get exception if you call Eval function with argument that doesn't exists in data source...

1 solution

Hi,
In your page create this method:
C#
protected string GetImageFullPath(object imageName)
{
	return Path.Combine(HttpRuntime.AppDomainAppVirtualPath, "img", imageName.ToString());
}

Then in markup use it like this:
HTML
ImageUrl='<%# GetImageFullPath(Eval("r_image")) %>'


This way you can set break point, debug and see whats your method is returning to you...
 
Share this answer
 
v2
Comments
egyptioncoder 4-Feb-12 19:13pm    
that`s`ll not help :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900