Answered by:
How can I assign the iamge url from MS Acsess to Image button in ASP.NET

Question
-
User-1387900100 posted
hi,
I am new to .NEt, I am doing a classifieds website and tried to save the image in server,in a seperate folder and stored that address in MS access databse.when I wanted to display that image in a gridview,its not showing the image.It would be great if some one suggests the solution for it.
In the seperate column when Ia m trying to see the image location using bound field,its displaying C:\websites\Azango\user_images\rj.jpg, but where as its not showing the image in the item template field.please help me in displaying the image.
Thanks in advance.
<asp:GridView ID="GridView2" PageSize="10" style="text-align:left;" EmptyDataText="No results found." runat="server" DataSourceID="AccessDataSource2"
AllowPaging="True" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" Width="758px" >
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:TemplateField HeaderText="Reserve">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" style="border:none; width:100px; height:50px;" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "photos") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="price" HeaderText="price" SortExpression="price" />
<asp:BoundField DataField="photos" HeaderText="photos" SortExpression="photos" />
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile="~/access_db/classifieds.mdb"
SelectCommand="SELECT [Title], [price], [photos] FROM [post_tbl] WHERE (([city] = ?) AND ([catg] = ?) AND ([subcat] = ?)) ORDER BY [time]">
<SelectParameters>
<asp:SessionParameter Name="city" SessionField="city" Type="String" />
<asp:QueryStringParameter Name="catg" QueryStringField="mcatg" Type="String" />
<asp:QueryStringParameter Name="subcat" QueryStringField="msubcatg"
Type="String" />
</SelectParameters>
</asp:AccessDataSource>
Monday, June 21, 2010 5:47 AM
Answers
All replies
-
User-1725039537 posted
Link: http://www.codeproject.com/KB/aspnet/GridImage.aspx
this above page wuold be kind o okay. Please try it.
Monday, June 21, 2010 7:38 AM -
User3866881 posted
Hey, since you didn't save images in the db, maybe you should try to use this:
<asp:ImageButton ID="ImageButton1" runat="server" style="border:none; width:100px; height:50px;" ImageUrl='<%#Eval("Image","/ImageFolder/{0}") %>' />
And Image field is a full filename for an image stored in the ImageFolder, like abc.jpg
Monday, June 21, 2010 9:25 PM -
User1495804863 posted
Hi,
You can do it like this....
<ItemTemplate> <asp:Image runat="server" ID="Image1" ImageUrl='<%# Eval("st_picPath","~/pics/{0}.jpg") %>' /> </ItemTemplate> <asp:ImageField DataImageUrlField="st_picPath" DataImageUrlFormatString="~/pics/{0}.jpg"></asp:ImageField>
Tuesday, June 22, 2010 12:02 AM -
User-1387900100 posted
hi thanks for the reply,
but still its not diaplying the image.
I used following code to save the iamge in user_images folder,
string path1=Server.MapPath("~/user_images/" + photo1.PostedFile.FileName);
photo1.SaveAs(path1);
and after that I have saved the image path in the data base.
and
whn I am trying to show that image in details view,its not displaying the imageI used the following code.
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="167px"
CellPadding="4" ForeColor="#333333" GridLines="None"
AutoGenerateRows="False" DataSourceID="AccessDataSource1">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<CommandRowStyle BackColor="#FFFFC0" Font-Bold="True" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<FieldHeaderStyle BackColor="#FFFF99" Font-Bold="True" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<Fields>
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="price" HeaderText="price" SortExpression="price" />
<asp:BoundField DataField="Description" HeaderText="Description"
SortExpression="Description" />
<asp:BoundField DataField="photos" HeaderText="photos"
SortExpression="photos" />
<asp:BoundField DataField="EMail" HeaderText="EMail" SortExpression="EMail" />
<asp:BoundField DataField="phone" HeaderText="phone" SortExpression="phone" />
<asp:BoundField DataField="city" HeaderText="city" SortExpression="city" />
<asp:BoundField DataField="zipcode" HeaderText="zipcode"
SortExpression="zipcode" />
<asp:BoundField DataField="dat" HeaderText="Posted Date" SortExpression="dat" />
<asp:BoundField DataField="mont" HeaderText="Posted Month" SortExpression="mont" />
<asp:TemplateField HeaderText="Image" ><ItemTemplate >
<asp:Image style="border:none; width:100px; height:50px;" ID="Image1" runat="server" ImageUrl='<%# Eval("photos") %>' />
</ItemTemplate></asp:TemplateField>
</Fields>
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:DetailsView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/access_db/classifieds.mdb"
SelectCommand="SELECT [Title], [price], [Description], [photos], [EMail], [phone], [city], [zipcode], [dat], [mont],[imag] FROM [post_tbl] WHERE ([ID] = ?) ORDER BY [time]">
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="id" Type="Int32" />
</SelectParameters>
</asp:AccessDataSource>It would be great if some one can help me.
Tuesday, June 22, 2010 5:16 AM -