Click here to Skip to main content
13,409,451 members (40,027 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
I am developing a website in asp.net.I have taken a 'Datalist' control for uploading the images.But when the no. of images increases then the problem create so I want to give the Paging . So how to give the Paging.

Here is the whole code where i want to apply the Datalist Paging:------So Now You can understand that what I Really want?
So give me the proper solution.

The aspx code of the Datalist for uploading the images:----

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

    RepeatColumns="4" BackColor="White" BorderColor="#CC9966" BorderStyle="Solid"

     BorderWidth="1px" CellPadding="4" GridLines="Both"

        onitemcommand="DataList1_ItemCommand" Font-Size="Small" >
        <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
        <ItemStyle BackColor="White" ForeColor="#330099" />
        <SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
        <ItemTemplate>
          <asp:ImageButton ID="ImageButton1" runat="server" Height="120px" Width="180px" ImageUrl=' <%#Eval("url")%>' CommandName="select" CommandArgument='<%#Eval("url") %>' />
            <br />
             Head Line : <%#Eval("headline") %>
             <br />
             Publication : <%#Eval("publication") %>
             <br />
             Edition : <%#Eval("edition") %>
             <br />
             Date : <%#Eval("date") %>
            </ItemTemplate>
        </asp:DataList>






The code behind(aspx.cs)code is given below:-----

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            imagebind2();
            
        }
    }

    private void imagebind2()
    {
        try
        {
            string selectSQL = "SELECT headline,publication,edition,date,url FROM competion";
            SqlConnection cnn = new SqlConnection(connectionString);
            SqlDataAdapter adp = new SqlDataAdapter(selectSQL, cnn);
            DataSet ds = new DataSet();
            adp.Fill(ds);
            DataList1.DataSource = ds;
            DataList1.DataBind();
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }

    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "select")
            {
                SqlConnection cnn = new SqlConnection(connectionString);
                string selectSQL = "SELECT publication,edition,date,url FROM competion where url='" + e.CommandArgument.ToString() + "'";
                SqlDataAdapter adp = new SqlDataAdapter(selectSQL, cnn);
                DataTable dt = new DataTable();
                adp.Fill(dt);
                DataRow dr = dt.Rows[0];

                //Image1.ImageUrl =dr["url"].ToString();
                //Label1.Text=dr["publication"].ToString();
                //Label2.Text=dr["edition"].ToString();
                //Label3.Text = dr["date"].ToString();

                Session["url1"] = dr["url"].ToString();
                //Session["publication"]=dr["publication"].ToString();
                //Session["edition"] = dr["edition"].ToString();
                //Session["date"] = dr["date"].ToString();
                Response.Redirect("~/ImageDiscription.aspx");

                //on page load
                //Image1.ImageUrl=Session["url1"].ToString();

            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
Posted 23-Sep-11 22:37pm
Updated 25-Sep-11 21:31pm
v4
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

this definitely helps:
http://forums.asp.net/t/1108198.aspx[^]
  Permalink  
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

//fill datalist with 10 record per page.

 PagedDataSource pds = new PagedDataSource();
pds.DataSource = mydatatable.DefaultView;
        pds.AllowPaging = true;
        pds.PageSize = 10;
        pds.CurrentPageIndex = currentpage;
        count = pds.PageCount;       
        DataList1.DataSource = pds;
        DataList1.DataBind();


//next button click_event
if (Session["cp"] != null)
        {
            currentpage = (int)(Session["cp"]);       
        }
        else
        {
            currentpage = 0;
        }         
            currentpage += 1;
            Session.Add("cp", currentpage);
            filllist();           
        }
        
//previous button_click event
if (Session["cp"] != null)
        {
            currentpage = (int)(Session["cp"]);       
        }
        else
        {
            currentpage = 0;
        }         
            currentpage -= 1;
            Session.Add("cp", currentpage);
            filllist();           
        }
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

  Permalink  
Comments
deepureddy18 1-Jun-12 7:54am
   
check it
http://www.netomatix.com/development/datalistpaging.aspx[^]
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 7

Go through below link

http://www.aspsnippets.com/Articles/Implement-Paging-in-DataList-control-in-ASPNet.aspx
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02-2016 | 2.8.180212.1 | Last Updated 28 Sep 2015
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100