Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 492
  • Last Modified:

custom paging/normal paging on Datalist

Hi,
I have created a datalist for displaying the results of my searches for a new job board site i am creating.
I have all results returning into  a Datalist. Now i understand that a datalist does not have the inbuilt ability to add paging onto the list.
Please could someone guide me though how i would go about adding paging onto my datalist.

Many thanks
<asp:DataList ID="DataList1" runat="server" BackColor="White" 
            BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4" 
            GridLines="Horizontal" RepeatLayout="Flow" Width="600px" 
            onselectedindexchanged="DataList1_SelectedIndexChanged" 
            UseAccessibleHeader="True" DataKeyField="jobid" Font-Bold="False" Font-Italic="False" 
                                Font-Names="Arial" Font-Overline="False" Font-Size="Smaller" 
                                Font-Strikeout="False" Font-Underline="False" 
            style="text-align: center">
            <FooterStyle BackColor="White" ForeColor="#333333" />
            <ItemTemplate>
              
              
                <br />  <b>Job Title</b>:
                <asp:Label ID="jobtitleLabel" runat="server" Text='<%# Bind("jobtitle") %>' />
                <b>Job Location</b>:
                <asp:Label ID="Label1" runat="server" 
                            Text='<%# Bind("location") %>' />
                <br />
                                <br />
                                
                <b>Job Description</b>:<br />
                <asp:Label ID="publishedjobdescriptionLabel" runat="server" 
                            Text='<%# Bind("description") %>' />
               
                   
                   
                    <asp:LinkButton ID="LinkButton1" CommandName="DetailsViewRedirect" runat="server" CommandArgument='<%# Bind("jobid") %>' oncommand="LinkButton1_Command">more</asp:LinkButton>
 
 
                <br />
                <br />
              
                <hr />
            </ItemTemplate>
            <ItemStyle BackColor="White" ForeColor="#333333" />
            <SeparatorStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" 
                Font-Strikeout="False" Font-Underline="False" ForeColor="Aqua" />
            <SelectedItemStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
        </asp:DataList>

Open in new window

0
leap29
Asked:
leap29
  • 4
  • 3
1 Solution
 
leap29Author Commented:
hi, thanks for the links but none are really relevant,
I am coding in C# and have already built my datalist. have you any other examples or can you help with the code?
 
thanks
0
 
leap29Author Commented:
hi, i have the following code after following another tutorial.
 
when i run the page it just crashes my internet explorer

   
        PagedDataSource objPage = new PagedDataSource();
        try
        {
            DataSet ds = new DataSet();
            objPage.AllowPaging = true;
            objPage.DataSource = objPage;
            objPage.PageSize = 100;
            objPage.CurrentPageIndex = CurrentPage;
            DataList2.DataSource = objPage;
            DataList2.DataKeyField = "Jobid";
            DataList2.DataBind();
        }
        catch (Exception ex)
        {
            throw ex;
        }
       
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
David H.H.LeeCommented:
Hi leap29,
>>..have you any other examples or can you help with the code?
It depend how you control the paging features that required. You can refer the articles that posted for the idea how to implement paging functionality inside your application.
>>...when i run the page it just crashes my internet explorer
what is the estimated results that return from your datasource? Lastly, what is the errors details that returned from screen?

0
 
leap29Author Commented:
Hi,
Attached is a sample of my code behind file. I am returning anywhere between 10 - 500 records. I think my problem with using this code is that it expects a single table to be giving it the data.
I am using a stored procedure which fills a datatable and returns the datatable to a datalist.
not sure if what i am doing is 100% correct.
 
thanks for looking

  public int CurrentPage
    {
        get
        {
            // look for current page in ViewState
            object o = this.ViewState["_CurrentPage"];
            if (o == null)
                return 0; // default page index of 0
            else
                return (int)o;
        }
 
        set
        {
            this.ViewState["_CurrentPage"] = value;
        }
    } 
    
    protected void Button3_Click(object sender, EventArgs e)
    {
        string strConn = "";
        string keyword = TextBox1.Text;
        string location = TextBox2.Text;
        strConn = ConfigurationManager.ConnectionStrings["SQL03"].ConnectionString;
        SqlConnection cnn = new SqlConnection(strConn);
        cnn.Open();
 
        System.Data.SqlClient.SqlCommand objCmd = new System.Data.SqlClient.SqlCommand("sp_leap29_jobdetails_quicksearch", cnn);
 
        SqlDataAdapter da = new SqlDataAdapter(objCmd);
        objCmd.CommandType = System.Data.CommandType.StoredProcedure;
        objCmd.Parameters.Add(new SqlParameter("@keyword", keyword));
        objCmd.Parameters.Add(new SqlParameter("@location", location));
 
        DataTable dt = new DataTable();
        da.Fill(dt);
 
        //DataList2.DataSource = dt;
        //DataList2.DataBind();
        
       
        
        
        
        
        PagedDataSource objPage = new PagedDataSource();
 
        try
        {
            DataSet ds = new DataSet();
 
            objPage.AllowPaging = true;
            objPage.DataSource = ds.Tables["jobs"].DefaultView;
            objPage.PageSize = 8;
 
            objPage.CurrentPageIndex = CurrentPage;
 
            DataList2.DataSource = objPage;
            DataList2.DataKeyField = "jobid";
            DataList2.DataBind();
 
        }
 
        catch (Exception ex)
        {
            throw ex;
        }
       
    }

Open in new window

0
 
David H.H.LeeCommented:
Hi leap29,
You can refer this page for more details:
http://www.aspdotnetcodes.com/DataList_Dynamic_Paging_PagedDataSource.aspx
0
 
leap29Author Commented:
it was working for the past 24hrs it was me being an idiot and forgetting to tell my datatable to fill..... ooops :)

thanks for your help
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now