单击datalist中的图像,然后在另一页中查看包含详细信息的单击图像 [英] Click image in datalist and view the clicked image with detail in another page

查看:89
本文介绍了单击datalist中的图像,然后在另一页中查看包含详细信息的单击图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是初学者



我在数据库中有图像,我从数据库中获取。我希望能够点击一张图片,这张图片可以带我到一个细节页面,同时显示相同的图像,也会显示有关图像的信息。



如何在我的详细信息页面中显示图像?



i保存我数据库中我的文件夹中的图像名称,例如巧克力.jpg



这是我目前的代码,不确定它是否正确的做法



in product.aspx

< ItemTemplate> 


< asp:HyperLink ID =hlnkNavigateUrl ='<%# string .Format(ViewProductDetail.aspx?ProductID = { 0 } ,Eval(ProductID))%> runat =server>

< asp:Image ID =Image1runat =serverHeight =127px
ImageUrl ='<%#Bind(Picture,〜/ Image / { 0 })%> '宽度=129px/>

< / asp:HyperLink >

< br />
< asp:Label ID =ProductNameLabelrunat =server
Text ='<%#Eval(ProductName) %> ' />
< br />
< asp:Label ID =PriceLabelrunat =server
Text ='<%#Eval(Price, { 0 C} )%>' />
< br />
< br />
< / ItemTemplate >




产品详细信息
产品详情

<前lang =c#> protected void Page_Load( object sender,EventArgs e)
{
if (Request.QueryString.Count!= 0
{

int ProductID = Convert.ToInt32(Request.QueryString [ ProductID]);
if (!IsPostBack)
{
string strConnectionString = ConfigurationManager .ConnectionStrings [ ConnectionString]。ConnectionString;
SqlConnection myConnect = new SqlConnection(strConnectionString);
SqlCommand cmd = new SqlCommand( SELECT ProductID,ProductName,Price,Description,Picture FROM Product WHERE ProductID = + ProductID,myConnect);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, Product);

myConnect.Open();
SqlDataReader reader = cmd.ExecuteReader();

if (reader.Read())
{

txtProductName.Text = reader [< span class =code-string> ProductName]。ToString();
txtPrice.Text = reader [ Price]。ToString();
txtDescription.Text = reader [ 描述]。ToString();
图片????

}
}
}
}





我的ProductDetail.aspx是否需要另一个datalist?

解决方案

代码似乎可以满足您的要求。



第二个问题是详细信息页面中是否需要数据列表 - 这是不需要的,因为一次只能显示一个详细图像。



您可以轻松地使用带有div内部路径的图像控件,并附带一些文字控件或paragragh来显示其他细节。



希望这可以帮助你...


HI


试试这个,




母页中的




 <   asp:HyperLink     ID   =  hlnk    NavigateUrl   ='  <% string  .Format(  ViewProductDetail.aspx?ProductID = {0}& Picture = {1},Eval(  ProductID),Eval( 图片))%> '    runat   =  server >  





详情页面:





  int  ProductID = Convert.ToInt32(Request.QueryString [ 的ProductID]); 
string picture = 〜/ Image / + Request.QueryString [ Picture];
Image1.ImageUrl = picture;


Hi, i'm a beginner here

I have images in datalist which i get from database. I want to be able to click on an image which would than take me to a detail page where the same image would be displayed and the information about the image would be displayed too.

how do i display the image in my detail page ?

i save the image name from my folder in my database , e.g chocolate.jpg

this is my current code not sure if its the correct way of doing it

in product.aspx

<ItemTemplate>

                    
                    <asp:HyperLink ID="hlnk" NavigateUrl='<%# string.Format("ViewProductDetail.aspx?ProductID={0}", Eval("ProductID")) %>' runat="server">
                    
             <asp:Image ID="Image1" runat="server" Height="127px" 
                    ImageUrl='<%# Bind("Picture", "~/Image/{0}") %>' Width="129px" />
                    
                    </asp:HyperLink>

                    <br />
            <asp:Label ID="ProductNameLabel" runat="server" 
                Text='<%# Eval("ProductName") %>' />
            <br />
            <asp:Label ID="PriceLabel" runat="server" 
                Text='<%# Eval("Price","{0:C}") %>' />
            <br />
            <br />
        </ItemTemplate>



in ProductDetail.aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString.Count != 0)
        {

            int ProductID = Convert.ToInt32(Request.QueryString["ProductID"]);
            if (!IsPostBack)
            {
                string strConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                SqlConnection myConnect = new SqlConnection(strConnectionString);
                SqlCommand cmd = new SqlCommand("SELECT ProductID, ProductName, Price, Description, Picture FROM Product WHERE ProductID=" + ProductID, myConnect);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds, "Product");

                myConnect.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                if (reader.Read())
                {

                    txtProductName.Text = reader["ProductName"].ToString();
                    txtPrice.Text = reader["Price"].ToString();
                    txtDescription.Text = reader["Description"].ToString();
                    image????

                }
            }
        }
    }



does my ProductDetail.aspx require another datalist?

解决方案

The code seems to be fine for your requirement.

The second question is whether a datalist is needed in the Details page- which is not required since there is only one detailed image to display at a time.

You can easily use a image control with the path within a div accompanied with some literal controls or paragragh to display the other details.

Hope this helps you...


HI
try like this,


in parent page:

<asp:HyperLink ID="hlnk" NavigateUrl='<%# string.Format("ViewProductDetail.aspx?ProductID={0}&Picture={1}", Eval("ProductID"), Eval("Picture")) %>' runat="server">



in details page:


int ProductID = Convert.ToInt32(Request.QueryString["ProductID"]);
                string picture = "~/Image/" + Request.QueryString["Picture"];
                Image1.ImageUrl = picture;


这篇关于单击datalist中的图像,然后在另一页中查看包含详细信息的单击图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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