如何在不使用处理程序类的情况下在gridview模板字段内显示图像? [英] How to display image inside gridview template field without using handler class?
本文介绍了如何在不使用处理程序类的情况下在gridview模板字段内显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在gridview的模板字段中显示图像。我想知道如何传递Image控件的Image url。
这就是我所做的 -
ASPX页面:
I want to display image within template field of the gridview. I want to know how can I pass Image url for the Image control. This is what I am doing- ASPX Page:
<asp:GridView ID="GridView1" runat="server" Width="1000px" CellPadding="4"
ForeColor="#333333" GridLines="None" AutoGenerateColumns="False">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Height="122px"
ImageUrl="" Width="148px" />
<br />
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="300px" />
</asp:TemplateField></asp:GridView>
.CS代码:
public void show()
{
try
{
dt = g1.return_dt("select * from tbl_item_post where Ref_No is not null order by company");
if (dt.Rows.Count > 0)
{
pic1 = Convert.ToString(dt.Rows[0]["image_url"]);
adsource = new PagedDataSource();
adsource.DataSource = dt.DefaultView;
adsource.PageSize = 10;
GridView1.DataSource = adsource;
GridView1.DataBind();
}
else
{
GridView1.DataSource = null;
GridView1.DataBind();
}
}
catch (Exception ex)
{
ex.ToString();
}
}
请指导我如何做到这一点。
Please Guide me how to do this.
推荐答案
您可以像这样直接绑定gridview中的图片url
You can directly bind the image url in the gridview like this
<asp:Image ID="Image1" runat="server" Height="122px" ImageUrl='<%# Eval("image_url","~/Images/{0}") %>' Width="148px" />
您可以随时创建正确的网址,具体取决于您在数据库中保存的值图片。
You can always able to create the correct url depending upon what values are you saving in the database for the image.
这篇关于如何在不使用处理程序类的情况下在gridview模板字段内显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文