Hi all!
I'm currently designing a link index/database along with a news/CMS system, and was trying to determine how to do a couple of things, mainly pagination...
I know you can enable pagination when using a datagrid, but datagrids IMHO are ugly as sin, and I prefer the old fasioned way of returning records by coding it myself. So that's what i've done. I've coded a system that will display categories, etc at the click of a link.
What i'd like to do, since SQL doesn't have the ability to limit the # of records returned by default (like MySQL does) and rather than use the top 10 or 20, which only pulls the stuff from the beginning of the DB on out....I'd like to set it up so I can do some pagination.
I've search around the web and couldn't exactly find a good, solid tutorial or information on really implementing this.
I did find one decent article,
http://www.aprogrammersjournal.com/article.aspx?id=67, but there must be a simpler, easier method of doing the same thing...
I'm also using C# should that matter at all.
Basically, here is what I have written thus far that shoots out the results of a database used for links..
Basically the page initially displays the catagories available for this particular section from a master categories table, and then once a user clicks on one of the categories, goes and fetches it from another table accordingly.
CODE
SqlConnection con = null;
SqlCommand cmd = null;
SqlDataReader rd = null;
try {
con = new SqlConnection("server=myserver;uid=myusername;" +
"pwd=password;database=mydatabase");
cmd = new SqlCommand("SELECT * FROM resources WHERE mastercat ='Forms' AND cat ='"+Request.QueryString["cat"]+"'", con);
con.Open();
rd = cmd.ExecuteReader();
while(rd.Read()) {
Response.Write("<table border=1>");
Response.Write("<tr><td> ");
Response.Write(rd.GetString(6));
Response.Write("</td></tr> ");
Response.Write("<tr><td> ");
Response.Write(rd.GetString(7));
Response.Write("</td></tr> ");
Response.Write("<tr><td><a href="+rd.GetString(5)+" target=_blank>");
Response.Write("Download</a></td></tr> ");
Response.Write("<br></table> ");
}
} catch (Exception e) {
Response.Write("<p><font color=\"red\">Err: ");
Response.Write(e.Message);
Response.Write("</font></p>");
} finally {
if(rd != null)
rd.Close();
if(con != null)
con.Close();
}
}
It's set up to get the name of the link, a description, and then the link itself.
What I want to do is paginate it, so that say only about 3-5 links will show at one time.
I haven't found a good way of doing this yet, and I'd like to do this, as I can carry it over to my news section as well...and that brings up my other question.
Currently, my news system just displays the news thats in a database. I have fields that desginate the author, title, intro, full body, time/date submitted. What is a good way to get just the latest news...e.g. if the news is older than today but there was no news posted sans maybe a week ago, just display that...? What is a good way to do that?
Thanks for any feedback!