Thursday, September 3, 2009

pagging in datalist....

using System;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Gallery_sports : System.Web.UI.Page
{

static int trow = 0, cindx, pgsize;
ADOC fm = new ADOC();

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
pgsize = 9;
cindx = 0;
imageload();
}
}

private void imageload()
{
try
{
if (!string.IsNullOrEmpty(Session["Imgtyp"].ToString()))
{

if (Session["Imgtyp"].ToString() == "InterSchool")
{
load_image("Inter_school");
this.Label1.Text = "Inter School Competion";
}
else if (Session["Imgtyp"].ToString() == "Saraswati")
{
load_image("saraswati_pooja");
this.Label1.Text = "Saraawati Pooja";
}

else if (Session["Imgtyp"].ToString() == "Sports")
{

load_image("Sports");
this.Label1.Text = "Sports";
}
else if (Session["Imgtyp"].ToString() == "IntraSchool")
{

load_image("Intra_school");
this.Label1.Text = "Intra School Competion";
}
else if (Session["Imgtyp"].ToString() == "Bosco_evergreen")
{

load_image("Bosco_evergreen");
this.Label1.Text = "Bosco Evergreen";
}
}
}

catch
{ load_image("Sports"); }
}

#region"------------LoadImage-----------------"



private void load_image(string strpt)
{
SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["strConn"]);
SqlDataAdapter objDA = new SqlDataAdapter("exec sp_Photo_gallery '','"+strpt+"','','','',4,''", objConn);
DataSet objDS = new DataSet();

if (!Page.IsPostBack)
{
objDA.Fill(objDS);
trow = objDS.Tables[0].Rows.Count;
objDS = null;
objDS = new DataSet();
}

objDA.Fill(objDS, cindx, pgsize, "Photo_gallery");
this.dList.DataSource = objDS.Tables[0].DefaultView;
this.dList.DataBind();
objConn.Close();


}

public void ShowNext(object s, EventArgs e)
{
if (cindx + 1 <>
{
cindx = cindx + pgsize;
}

imageload();
}

public void ShowPrevious(object s, EventArgs e)
{
cindx = cindx - pgsize;
if (cindx <>
{
cindx = 0;
}

imageload();
}

# region"============DataList Page Status Check ================"

private void DataList_Status(int cindx, int pgsize, int trow, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
Label lbl = (Label)e.Item.FindControl("lblStatus");

lbl.Text = "";
lbl.Text = "Total Records:" + trow;
lbl.Text += " - Showing Page: ";
lbl.Text += Convert.ToInt32((cindx / pgsize) + 1).ToString();
lbl.Text += " of ";

Button btn_nxt = (Button)e.Item.FindControl("Button1");
if ((trow % pgsize) > 0)
{
lbl.Text += Convert.ToInt32((trow / pgsize) + 1).ToString();
if (Convert.ToInt32((cindx / pgsize) + 1).ToString() == Convert.ToInt32((trow / pgsize) + 1).ToString())
{

btn_nxt.Enabled = false;
}

}
else
{
lbl.Text += Convert.ToInt32(trow / pgsize).ToString();
if (Convert.ToInt32((cindx / pgsize) + 1).ToString() == Convert.ToInt32((trow / pgsize)).ToString())
{

btn_nxt.Enabled = false;
}
}
lbl.Text += "";


Button btn_prv = (Button)e.Item.FindControl("Button2");
if ((cindx + 1) == 1)
{

btn_prv.Enabled = false;
}
else
{
btn_prv.Enabled = true;
}
}
}

#endregion


#endregion

protected void Button1_Click(object sender, EventArgs e)
{
ShowNext(sender, e);
}

protected void Button2_Click(object sender, EventArgs e)
{
ShowPrevious(sender, e);
}

protected void dlImages_ItemCreated(object sender, DataListItemEventArgs e)
{
DataList_Status(cindx, pgsize, trow, e);
}
}

No comments: