Click here to Skip to main content
15,909,325 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
hello friends ,
I am working on a page where i have three datalist controls .I am binding data from database .I have 2 probulms in using them .
1. I am using page data source class for paging with all three datalist control ,when i am clicking on first or next button of any of datalist control ,it is working for all three control.Means if i click on first datalist controls next button then all three datalist controls shows there next page .

2. i want to add images to the all three datalist controls from codebehind.how to do it .Image name is stored in database and image is stored in folder on my website.Thanks in advance friends .
This is my code :
ASP.NET
<table width="100%">
<tr>
<td>
Hot Deals
</td>
</tr>
<tr>
<td width="100%">
<asp:DataList ID="dhotlist" GridLines="Horizontal" RepeatColumns="4" Width="100%"
 RepeatDirection="Horizontal"   runat="server" 
        onitemdatabound="dhotlist_ItemDataBound">
<itemtemplate>
 

<a href="ProductDescription.aspx" hold=" /><asp:Image ID=" imgisbn=" Height=" 200px=" Width=" 120px=" runat=" server=" /><br mode=" productdescription.aspx=" ><%# Eval(" cauthorname=")%></a><br mode=" lblproductauthorname=" runat=" cproductname=") %><br mode=" lblprice="  Runat=" lprice=") %><br mode=" lblafterdiscount="  Runat=" aftrdiscountprice=")%><br mode=" btnprev=" Text=" prev=" OnClick=" prev_click=" runat=" lblcurrentpage=" runat=" btnnext=" Text=" next="" next_click=" runat=" dlistbestseller=" GridLines=" horizontal=" RepeatColumns=" 4=" Width=">
<asp:Image ID="imgisbnBS" Height="200px" Width="120px" runat="server" />
</a><br />
<a href="ProductDescription.aspx"><%# Eval("cauthorname")%></a>

<asp:Label ID="lblBProductAuthorName" runat="server" >   <%# Eval("cproductname") %>

<br />
 
<asp:Label ID="lblBprice"  Runat="server"> <%# Eval("lprice") %>

<br />

<asp:Label ID="lblBafterdiscount"  Runat="server"> <%# Eval("aftrdiscountprice")%>

<br />
 

</itemtemplate>

<asp:LinkButton id="linbuttonB1" Text="<< Prev"  runat="server" 
        onclick="linbuttonB1_Click"/>
<asp:Label id="lblCurrentPageBS" runat="server"/>
<asp:LinkButton id="LinkButtonB2" Text="Next >>"  runat="server" 
        onclick="LinkButtonB2_Click"/>
</td>
</tr>

////////////////////////////////////////   Forth Coming Products////////////////////////////




<tr>
<td>
Forthcoming Products
</td>
</tr>
<tr>
<td width="100%">
<asp:DataList ID="DlistFcoming" GridLines="Horizontal" RepeatColumns="4" Width="100%"
 RepeatDirection="Horizontal"   runat="server" 
      >
<itemtemplate>


        }
        return myimagePath;
    }

    public string returnImage2(string imagepath, string isbn)
    {

        string myimagePath = imagepath;
        if (File.Exists(Server.MapPath("UploadedImage/" + isbn + ".gif")))
        {
            myimagePath = "UploadedImage/" + isbn + ".gif";
        }
        else if (File.Exists(Server.MapPath("UploadedImage/" + isbn + ".jpg")))
        {
            myimagePath = "UploadedImage/" + isbn + ".jpg";
        }
        else if (File.Exists(Server.MapPath(imagepath)))
        {
            myimagePath = imagepath;
        }
        else if (!File.Exists(Server.MapPath(imagepath)))
        {
            myimagePath = "images/noImage2.gif";
        }
        return myimagePath;
    }
    protected void dhotlist_ItemDataBound(object sender, DataListItemEventArgs e)
    {
   //         if (e.Item.ItemType == ListItemType.Item ||
   //e.Item.ItemType == ListItemType.AlternatingItem)
   //     {

   //         ((Image)e.Item.FindControl("Image2")).ImageUrl =
   //  returnImage2("UploadedImage/" + string(DataBinder.Eval( e.Item.DataItem,"cimage")),string(DataBinder.Eval( e.Item.DataItem,"cisbn")));
          
   //                }
    }
    protected void Prev_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pg.CurrentPageIndex - 1));
    }
    protected void Next_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pg.CurrentPageIndex + 1));
    }

    protected void linbuttonB1_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pgBS.CurrentPageIndex - 1));
    }
    protected void LinkButtonB2_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pgBS.CurrentPageIndex +1));
    }
    protected void LinkButtonF1_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pgFP.CurrentPageIndex - 1));
    }
    protected void LinkButtonF2_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pgFP.CurrentPageIndex + 1));
    }</itemtemplate></td></tr></table>
Posted
Updated 15-Nov-11 19:20pm
v2
Comments
Mehdi Gholam 16-Nov-11 1:21am    
EDIT -> fixed formatting

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