Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
5.00/5 (3 votes)
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:----

XML
<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
Updated 25-Sep-11 20:31pm
v4

this definitely helps:
http://forums.asp.net/t/1108198.aspx[^]
 
Share this answer
 
v3
C#
//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();           
        }
 
Share this answer
 
 
Share this answer
 
Comments
deepureddy18 1-Jun-12 7:54am    
check it
http://www.netomatix.com/development/datalistpaging.aspx[^]
Go through below link

http://forums.asp.net/t/1108198.aspx[^]
 
Share this answer
 
Go through below link

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

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