Hi,
This i my assignment i tried my level best to complete the task but i failed.
The pageing is not happening in this gridview code.(It is not going to next page)
the source code is below please do help
using System;
using System.Data;
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;
using System.Text;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
public partial class MemberPanel_cRechargeDetails : System.Web.UI.Page
{
int i, j;
DateTime dtToday;
string strDay;
String C;
string strMonth;
string strYear;
string strSqlDetails;
string strSortExp;
int intPageIndex;
long lngRegNo, lngIntroRegNo;
DataUtility objDUT = new DataUtility();
Utility objUT = new Utility();
protected void Page_Load(object sender, EventArgs e)
{
//-------------- Frefresh Page
//HtmlMeta metaTag=new HtmlMeta();
// metaTag.HttpEquiv = "Refresh";
// metaTag.Content = "60";
//Header.Controls.Add(metaTag);
//-----------------------------------
this.Page.Title = ConfigurationManager.AppSettings["titleBar"];
if (!IsPostBack)
{
if (Request.QueryString.Count > 0)
{
if (Request.QueryString[0].ToString() == "success")
{
lblMsg.Text = "Recharge coupon approved successfuly";
lblMsg.ForeColor = System.Drawing.Color.Green;
}
else if (Request.QueryString[0].ToString() == "error")
{
lblMsg.Text = "There are some error please check details";
}
}
this.ViewState["ps"] = "50";
this.ViewState["_asc"] = " DESC";
this.ViewState["By"] = " A.ACid";
CurrentPage = 1;
FillDDL();
lngRegNo = Convert.ToInt64(Session["MaxReg"]);
string strSQL = "select memcode,(fname+' '+isnull(lname,'')) as memname,loginid,regdate,introregno, mobile from member_master where regno=" + lngRegNo;
DataTable dt = objDUT.GetDataTable(strSQL);
lngRegNo = Convert.ToInt64(Session["MaxReg"].ToString());
if (Request.QueryString.Count > 0)
{
C = Request.QueryString[0].ToString();
BindData("select A.* From Member_Account A where A.crdb='D' and A.transType='recharge' and regno=" + lngRegNo + " order by A.ACID " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
}
else
{
BindData("select A.* From Member_Account A where A.crdb='D' and A.transType='recharge' and regno=" + lngRegNo + " order by A.ACID " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
}
//BindData("select A.*, M.LoginID, M.Mobile, SP.SpName From Member_Account A , Member_master M, Service_provider SP where M.regno=A.regno AND A.crdb='D' and A.transType='recharge' and A.trSP = SP.Spid and a.transdate>(getdate()-3) order by " + this.ViewState["By"].ToString() + " " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
//BindData("select A.* From Member_Account A where A.crdb='D' AND A.trStatus=1 and A.transType='recharge' and regno=" + lngRegNo + " order by A.ACID " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
//BindData("select A.*, M.LoginID, M.Mobile From Member_Account A , Member_master M where M.regno=A.regno AND A.crdb='D' and A.transType='recharge' order by " + this.ViewState["By"].ToString() + " " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
}
}
protected void BindData(string q, string pSize, string cPage)
{
DataSet ds = objDUT.GetDataSet(q);
this.ViewState["q"] = q;
//-----------------------------------
// Populate the repeater control with the Items DataSet
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = ds.Tables[0].DefaultView;
// Indicate that the data should be paged
objPds.AllowPaging = true;
// Set the number of items you wish to display per page
objPds.PageSize = Convert.ToInt32(pSize);
dropPcount.Items.Clear();
for (int b = 1; b <= objPds.PageCount; b++)
{
ListItem li = new ListItem(b.ToString(), b.ToString());
dropPcount.Items.Add(li);
}
dropPcount.Items.Insert(0, "Page");
dropPcount.SelectedIndex = CurrentPage;
//-------CurrentPage
lblCount.Text = dropPcount.SelectedValue + " of " + objPds.PageCount.ToString();
// Set the PagedDataSource's current page
objPds.CurrentPageIndex = Convert.ToInt32(dropPcount.SelectedValue) - 1;
//------Enable ------------
imgFirst.Enabled = !objPds.IsFirstPage;
imgPre.Enabled = !objPds.IsFirstPage;
imgLast.Enabled = !objPds.IsLastPage;
imgNext.Enabled = !objPds.IsLastPage;
//-----------------------
if (ds.Tables[0].Rows.Count > 0)
{
TABLE2.Visible = true;
//StateGrid.Visible = true; sd
StateGrid.DataSource = objPds;
StateGrid.DataBind();
}
else
{
TABLE2.Visible = false;
lblMsg.Text = "No Data found between selected date";
}
}
protected string Getno()
{
++i;
return i.ToString();
}
protected string Getno1()
{
++j;
return j.ToString();
}
//bimdata end
//protected string Getno()
//{
// ++i;
// return i.ToString();
//}
//protected string Getno1()
//{
// ++j;
// return j.ToString();
//}
protected void FillDDL()
{
try
{
for (int i = 2008; i <= Convert.ToInt32(System.DateTime.Today.Year); i++)
{
ddlFromYear.Items.Add(i.ToString());
ddlToYear.Items.Add(i.ToString());
}
ddlFromYear.SelectedValue = DateTime.Now.Year.ToString();
ddlToYear.SelectedValue = DateTime.Now.Year.ToString();
for (int j = 1; j <= 12; j++)
{
ddlFromMonth.Items.Add(j.ToString());
ddlToMonth.Items.Add(j.ToString());
}
ddlFromMonth.SelectedIndex = DateTime.Now.Month - 1;
ddlToMonth.SelectedIndex = DateTime.Now.Month - 1;
for (int k = 1; k <= 31; k++)
{
ddlFromDay.Items.Add(k.ToString());
ddlToDay.Items.Add(k.ToString());
}
ddlToDay.SelectedIndex = DateTime.UtcNow.AddHours(5.30).Day - 1;
ddlFromDay.SelectedIndex = DateTime.UtcNow.AddHours(5.30).Day - 1;
}
catch (Exception ex)
{
Response.Redirect("~/errorPage.aspx?error=" + ex.Message);
}
}
protected void btnShow_Click(object sender, EventArgs e)
{
try
{
string strFromDate = ddlFromMonth.SelectedValue.ToString() + "/" + ddlFromDay.SelectedValue.ToString() + "/" + ddlFromYear.SelectedItem.Text;
string strToDate = ddlToMonth.SelectedValue.ToString() + "/" + ddlToDay.SelectedValue.ToString() + "/" + ddlToYear.SelectedItem.Text;
if (checkDate(strFromDate))
{
lblMsg.Text = "Invalid From Date";
return;
}
else
{
lblMsg.Text = "";
}
if (checkDate(strToDate))
{
lblMsg.Text = "Invalid To Date";
return;
}
else
{
lblMsg.Text = "";
}
if (Convert.ToDateTime(strFromDate) <= Convert.ToDateTime(strToDate))
{
// lblMsg.Text = strFromDate;
BindData("select A.* From Member_Account A where A.crdb='D' and A.transType='recharge' and regno=" + lngRegNo + " order by A.ACID " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
//BindData("select A.*, M.LoginID, M.Mobile From Member_Account A , Member_master M where M.regno=A.regno and A.crdb='D' and A.transType='recharge' and (A.trDate between '" + strFromDate + "' and '" + Convert.ToDateTime(strToDate).AddDays(1) + "' ) order by " + this.ViewState["By"].ToString() + " " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
}
else
{
ltrlJavascript.Text = "<script language='javascript' type='text/javascript'>alert('From Date Must Be Less Than Or Equal To To Date');</script>";
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
// Response.Redirect("~/errorPage.aspx?error=" + ex.Message);
}
}
private bool checkDate(string dDate)
{
bool flag = false;
try
{
DateTime dcDate = Convert.ToDateTime(dDate);
flag = false;
}
catch { flag = true; }
return flag;
}
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 dropPage_SelectedIndexChanged(object sender, EventArgs e)
{
this.ViewState["ps"] = dropPage.SelectedValue;
CurrentPage = 1;
//FillGrid();
}
protected void dropPcount_SelectedIndexChanged(object sender, EventArgs e)
{
if (dropPcount.SelectedIndex != 0)
{
this.ViewState["ps"] = dropPage.SelectedValue;
int c = int.Parse(dropPcount.SelectedValue);
this.ViewState["_CurrentPage"] = c;
int pagesize = int.Parse(this.ViewState["ps"].ToString());
i = (c - 1) * pagesize;
BindData("select A.* From Member_Account A where A.crdb='D' and A.transType='recharge' and regno=" + lngRegNo + " order by A.ACID " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
//BindData("select A.*, M.LoginID, M.Mobile, SP.SpName From Member_Account A , Member_master M, Service_provider SP where M.regno=A.regno AND A.crdb='D' and A.transType='recharge' and A.trSP = SP.Spid and a.transdate>(getdate()-3) order by " + this.ViewState["By"].ToString() + " " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
//BindData("select A.* From Member_Account A where A.crdb='D' AND A.trStatus=1 and A.transType='recharge' and regno=" + lngRegNo + " order by A.ACID " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
//Response.Write(i.ToString());
// FillGrid();
}
}
protected void imgFirst_Click(object sender, ImageClickEventArgs e)
{
this.ViewState["ps"] = dropPage.SelectedValue;
this.ViewState["_CurrentPage"] = 1;
CurrentPage = 1;
int pagesize = int.Parse(this.ViewState["ps"].ToString());
i = (CurrentPage - 1) * pagesize;
BindData("select A.* From Member_Account A where A.crdb='D' and A.transType='recharge' and regno=" + lngRegNo + " order by A.ACID " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
//BindData("select A.*, M.LoginID, M.Mobile From Member_Account A , Member_master M where M.regno=A.regno AND A.crdb='D' and A.transType='recharge' order by " + this.ViewState["By"].ToString() + " " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
}
protected void imgLast_Click(object sender, ImageClickEventArgs e)
{
this.ViewState["ps"] = dropPage.SelectedValue;
int c = dropPcount.Items.Count - 1;
this.ViewState["_CurrentPage"] = c;
//----------- Reset Serial Number
CurrentPage = c;
int pagesize = int.Parse(this.ViewState["ps"].ToString());
i = (CurrentPage - 1) * pagesize;
BindData("select A.* From Member_Account A where A.crdb='D' and A.transType='recharge' and regno=" + lngRegNo + " order by A.ACID " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
//BindData("select A.*, M.LoginID, M.Mobile From Member_Account A , Member_master M where M.regno=A.regno AND A.crdb='D' and A.transType='recharge' order by " + this.ViewState["By"].ToString() + " " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
}
protected void imgPre_Click(object sender, ImageClickEventArgs e)
{
this.ViewState["ps"] = dropPage.SelectedValue;
int c = Convert.ToInt32(this.ViewState["_CurrentPage"].ToString()) - 1;
this.ViewState["_CurrentPage"] = c;
//----------- Reset Serial Number
CurrentPage = c;
int pagesize = int.Parse(this.ViewState["ps"].ToString());
i = (CurrentPage - 1) * pagesize;
BindData("select A.* From Member_Account A where A.crdb='D' and A.transType='recharge' and regno=" + lngRegNo + " order by A.ACID " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
//BindData("select A.*, M.LoginID, M.Mobile From Member_Account A , Member_master M where M.regno=A.regno AND A.crdb='D' and A.transType='recharge' order by " + this.ViewState["By"].ToString() + " " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
}
protected void imgNext_Click(object sender, ImageClickEventArgs e)
{
try
{
this.ViewState["ps"] = dropPage.SelectedValue;
int c = Convert.ToInt32(this.ViewState["_CurrentPage"].ToString()) + 1;
this.ViewState["_CurrentPage"] = c;
//----------- Reset Serial Number
CurrentPage = c;
int pagesize = int.Parse(this.ViewState["ps"].ToString());
i = (CurrentPage - 1) * pagesize;
BindData("select A.* From Member_Account A where A.crdb='D' and A.transType='recharge' and regno=" + lngRegNo + " order by A.ACID " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
// BindData("select A.*, M.LoginID, M.Mobile From Member_Account A , Member_master M where M.regno=A.regno AND A.crdb='D' and A.transType='recharge' order by " + this.ViewState["By"].ToString() + " " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
}
catch(Exception ex)
{
lblMsg.Text = ex.Message;
}
}
protected void StateGrid_ItemCommand(object source, RepeaterCommandEventArgs e)
{
string trcode = e.CommandArgument.ToString();
HiddenField1.Value = trcode;
Session["tr"] = trcode;
Label lblS = (Label)e.Item.FindControl("lblS");
if (lblS.Text.ToLower() == "pending")
{
Response.Redirect("RCApprove.aspx");
}
else
{
Response.Redirect("RC.aspx");
}
}
protected void StateGrid_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label lblS = (Label)e.Item.FindControl("lblS");
Label lblA = (Label)e.Item.FindControl("lblA");
if (lblA.Text != "")
{
lblA.Text = string.Format("{0:dd-MM-yyyy}", Convert.ToDateTime(lblA.Text));
}
if (lblS.Text == "0")
{
lblS.Text = "Pending";
lblS.ForeColor = Color.Blue ;
}
else if (lblS.Text == "2")
{
lblS.Text = "Rejected";
lblS.ForeColor = Color.Red;
}
else if (lblS.Text == "1")
{
lblS.Text = "Approved";
lblS.ForeColor = Color.Green;
}
}
}
protected void ddlSort_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlSort.SelectedValue.ToLower() == "trdate")
{
this.ViewState["By"] = " A.trDate";
}
else if (ddlSort.SelectedValue.ToLower() == "tramount")
{
this.ViewState["By"] = " A.trAmount";
}
else if (ddlSort.SelectedValue.ToLower() == "trStatus")
{
this.ViewState["By"] = " A.trStatus";
}
else if (ddlSort.SelectedValue.ToLower() == "loginid")
{
this.ViewState["By"] = " M.Loginid";
}
BindData("select A.* From Member_Account A where A.crdb='D' and A.transType='recharge' and regno=" + lngRegNo + " order by A.ACID " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
//BindData("select A.*, M.LoginID, M.Mobile From Member_Account A , Member_master M where M.regno=A.regno AND A.crdb='D' and A.transType='recharge' order by " + this.ViewState["By"].ToString() + " " + this.ViewState["_asc"].ToString() + "", this.ViewState["ps"].ToString(), "1");
}
}
-----
Advance thanks for the help