如何在数据列表控件中显示图像 [英] How to show image in datalist control

查看:133
本文介绍了如何在数据列表控件中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,

如何将数据从sql数据库绑定到数据列表控件.

我有一个数据列表控件,而里面有一个ASP图像控件.
在我的数据库中,我仅保存了图像名称.我需要在数据列表控件中显示图像.

我已经使用了下面提到的代码.



How to bind datas from sql database to datalist control.

I have a datalist control and inside that it has a asp image control.
In my database i have saved the Image name only. and i need to show the images in the datalist control.

I have used the code below mentioned.

<asp:Image ID="imgItem" runat="server" Height="75px" ImageUrl='../../Content/images/thumbs/sub/<%# Eval("Sub_Item_Img") %>' Width="75px" />



有什么方法可以使用asp图像控件显示图像. ?

当我使用此代码时,它不起作用.请帮助我....

谢谢

Dile.



Is there any way to show the image using asp image control. ?

When i used this code it didn''t works. please help me....

Thanks

Dile.

推荐答案

google it:

google it:

https://www.google.co.in/search?q=show+image+in+datalist+control&rlz=1C1AFAB_enIN490IN490&sugexp=chrome,mod=1&sourceid=chrome&ie=UTF-8[^]


<asp:DataList ID="DataList1" runat="server" RepeatColumns="3" RepeatDirection="Horizontal"

   Width="100%" BorderColor="#336699" BorderStyle="Solid" BorderWidth="2px">

   <ItemTemplate>
      <asp:Label ID="Label1" runat="server" Text='<%# Eval("ProductName") %>' Font-Bold="True"

         Font-Size="10pt" ForeColor="#336699" Width="100%" />
      <br />
      <asp:Image ID="Image1" runat="server"

         ImageUrl='<%# "GetImage.aspx?id=" + Eval("ProductID") %>' />
   </ItemTemplate>
   <ItemStyle HorizontalAlign="Center" VerticalAlign="Top"  />
</asp:DataList>


<div id="our_product_page_right_product_Product">
                    <asp:DataList ID="DataList1" runat="server" DataKeyField="p_id" RepeatDirection="Horizontal"

                        RepeatColumns="5" EnableViewState="true">
                        <ItemTemplate>
                            <div class="ourproductPAGE_product">
                                <!--Image -->
                                <asp:ImageButton CssClass="ourproductPAGE_productImage" ID="ImageButton1" ImageUrl='<%# Eval("p_image") %>'

                                    runat="server" PostBackUrl='<%# "ProductDetail.aspx?id=" +Eval("p_id") %>' />
                                <div class="ourproductPAGE_productInfo">
                                    <!--Name -->
                                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("p_name") %>' /><br />
                                    <!--Cost -->
                                    Cost:&nbsp;&#8377;&nbsp;<asp:Label ID="Label2" runat="server" Text='<%# Eval("p_cost") %>' />

                                </div>
                            </div>
                        </ItemTemplate>
                    </asp:DataList>
                </div>
                <div id="our_product_page_right_product_Previous-next">
                    <asp:Button ID="Prev" runat="server" Text="<<" OnClick="cmdPrev_Click"/>
                    <asp:Label ID="PageNo" runat="server" Text="Label"></asp:Label>
                    <asp:Button ID="Next" runat="server" Text=">>" OnClick="cmdNext_Click"/>
                </div>



<在demo.cs =">



<in demo.cs="">

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Our_Product : System.Web.UI.Page
{

    SqlConnection con;
    SqlDataAdapter da;
    DataSet ds;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            getdata();
        }
    }
    public int CurrentPage
    {
        get
        {
            object o = this.ViewState["_CurrentPage"];
            if (o == null)
                return 0;
            else
                return (int)o;
        }
        set
        {
            this.ViewState["_CurrentPage"] = value;
        }
    }
    public void getdata()
    {
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["Health_RazConnectionString"].ConnectionString);
        da = new SqlDataAdapter("select * from Organic_suppliment", con);
        con.Open();
        ds = new DataSet();
        da.Fill(ds, "Organic_suppliment");
        PagedDataSource objpds = new PagedDataSource();
        DataView dv = ds.Tables["Organic_suppliment"].DefaultView;
        objpds.DataSource = dv;
        objpds.AllowPaging = true;
        objpds.PageSize = 15;
        objpds.CurrentPageIndex = CurrentPage;
        PageNo.Text = "Page: " + (CurrentPage + 1).ToString() + " of " + objpds.PageCount.ToString();
        ArrayList mytotalpages = new ArrayList();
        for (int a = 1; a <= objpds.PageCount; a++)
        {
            mytotalpages.Add(a);
        }
        Prev.Enabled = !objpds.IsFirstPage;
        Next.Enabled = !objpds.IsLastPage;
        DataList1.DataSource = objpds;
        DataList1.DataBind();
    }
    protected void cmdPrev_Click(object sender, System.EventArgs e)
    {
        CurrentPage -= 1;
        getdata();
    }
    protected void cmdNext_Click(object sender, System.EventArgs e)
    {
        CurrentPage += 1;
        getdata();
    }
}


这篇关于如何在数据列表控件中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆