In Design page add two link button and a data list control i.e ".aspx" page
<asp:LinkButton ID="lnkPrevious" CssClass="footertxt" runat="server" onclick="lnkPrevious_Click">Previous</asp:LinkButton>
<asp:LinkButton ID="lnkNext" runat="server" CssClass="footertxt" onclick="lnkNext_Click">Next</asp:LinkButton>
<asp:DataList ID="DataList1" runat="server" RepeatColumns="3"
<ItemTemplate>
"In this section add your design "
</ItemTemplate>
</asp:DataList>
Now in .cs file write code given as :
public partial class test: System.Web.UI.Page
{
SqlDataAdapter da;
DataSet ds;
string conn;
static DataTable dt;
PagedDataSource pds;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindGrid();
}
public void BindGrid()
{
string conn = ConfigurationManager.ConnectionStrings["yourconnectioname"].ConnectionString;
string sql="Select * from Tbl_FreeRegister" ;
da = new SqlDataAdapter(sql, conn);
dt = new DataTable();
da.Fill(dt);
pds = new PagedDataSource();
pds.DataSource = dt.DefaultView;
pds.AllowPaging = true;
pds.PageSize = 9;
pds.CurrentPageIndex = CurrentPage;
lnkbtnPrevious.Enabled = !pds.IsFirstPage;
lnkbtnNext.Enabled = !pds.IsLastPage;
DataList1.DataSource = pds;
DataList1.DataBind();
}
//Define Property
public int CurrentPage
{
get
{
if (this.ViewState["CurrentPage"] == null)
return 0;
else
return Convert.ToInt16(this.ViewState["CurrentPage"].ToString());
}
set
{
this.ViewState["CurrentPage"] = value;
}
}
//linkbutton click event
protected void lnkPrevious_Click(object sender, EventArgs e)
{
CurrentPage -=1;
BindGrid();
}
protected void lnkNext_Click(object sender, EventArgs e)
{
CurrentPage += 1;
BindGrid();
}
}
<asp:LinkButton ID="lnkPrevious" CssClass="footertxt" runat="server" onclick="lnkPrevious_Click">Previous</asp:LinkButton>
<asp:LinkButton ID="lnkNext" runat="server" CssClass="footertxt" onclick="lnkNext_Click">Next</asp:LinkButton>
<asp:DataList ID="DataList1" runat="server" RepeatColumns="3"
<ItemTemplate>
"In this section add your design "
</ItemTemplate>
</asp:DataList>
Now in .cs file write code given as :
public partial class test: System.Web.UI.Page
{
SqlDataAdapter da;
DataSet ds;
string conn;
static DataTable dt;
PagedDataSource pds;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindGrid();
}
public void BindGrid()
{
string conn = ConfigurationManager.ConnectionStrings["yourconnectioname"].ConnectionString;
string sql="Select * from Tbl_FreeRegister" ;
da = new SqlDataAdapter(sql, conn);
dt = new DataTable();
da.Fill(dt);
pds = new PagedDataSource();
pds.DataSource = dt.DefaultView;
pds.AllowPaging = true;
pds.PageSize = 9;
pds.CurrentPageIndex = CurrentPage;
lnkbtnPrevious.Enabled = !pds.IsFirstPage;
lnkbtnNext.Enabled = !pds.IsLastPage;
DataList1.DataSource = pds;
DataList1.DataBind();
}
//Define Property
public int CurrentPage
{
get
{
if (this.ViewState["CurrentPage"] == null)
return 0;
else
return Convert.ToInt16(this.ViewState["CurrentPage"].ToString());
}
set
{
this.ViewState["CurrentPage"] = value;
}
}
//linkbutton click event
protected void lnkPrevious_Click(object sender, EventArgs e)
{
CurrentPage -=1;
BindGrid();
}
protected void lnkNext_Click(object sender, EventArgs e)
{
CurrentPage += 1;
BindGrid();
}
}
1 comments:
Thank you. The code is helped me a lot.
Post a Comment