The file will be stored in App_Code/Utility/
https://drive.google.com/file/d/1GCtAfzrV9Eqk6LUI0IitSihdP4Wch1sJ/view?usp=sharing
example below:-
private void GetCustomersPageWise(int pageIndex,string batchCode)
{
try
{
string constring = Luminious.Connection.Configuration.ConnectionString;
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("GetCustomersPageWise", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@batchCode", batchCode);
cmd.Parameters.AddWithValue("@PageIndex", pageIndex);
cmd.Parameters.AddWithValue("@PageSize", int.Parse(ddlPageSize.SelectedValue));
cmd.Parameters.Add("@RecordCount", SqlDbType.Int, 4);
cmd.Parameters["@RecordCount"].Direction = ParameterDirection.Output;
con.Open();
IDataReader idr = cmd.ExecuteReader();
GridView1.DataSource = idr;
GridView1.DataBind();
idr.Close();
con.Close();
int recordCount = Convert.ToInt32(cmd.Parameters["@RecordCount"].Value);
this.PopulatePager(recordCount, pageIndex);
}
}
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
GC.SuppressFinalize(this);
}
}
private void PopulatePager(int recordCount, int currentPage)
{
try
{
double dblPageCount = (double)((decimal)recordCount / decimal.Parse(ddlPageSize.SelectedValue));
int pageCount = (int)Math.Ceiling(dblPageCount);
List<ListItem> pages = new List<ListItem>();
if (pageCount > 0)
{
pages.Add(new ListItem("First", "1", currentPage > 1));
for (int i = 1; i <= pageCount; i++)
{
pages.Add(new ListItem(i.ToString(), i.ToString(), i != currentPage));
}
pages.Add(new ListItem("Last", pageCount.ToString(), currentPage < pageCount));
}
rptPager.DataSource = pages;
rptPager.DataBind();
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
}
}
protected void PageSize_Changed(object sender, EventArgs e)
{
this.GetCustomersPageWise(1,drp_batch.SelectedIndex>0?drp_batch.SelectedItem.Text.Trim():null);
}
protected void Page_Changed(object sender, EventArgs e)
{
int pageIndex = int.Parse((sender as LinkButton).CommandArgument);
this.GetCustomersPageWise(pageIndex, drp_batch.SelectedIndex > 0 ? drp_batch.SelectedItem.Text.Trim() : null);
}
No comments:
Post a Comment