first in design page:
<asp:Label ID="error" runat="server" Text=""></asp:Label>
<div id="selector1" style="font-family:Tahoma;
font-size:15px;
font-weight:bold">
Events and Exhibitions
</div>
<div id="selector" align="center" >
<asp:DataList ID="DataList1" runat="server" Width="627px" >
<ItemTemplate>
<div id="selector2">
<div id="div1" style="padding-left:5px;">
<asp:Label ID="label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "SE_eventname")%>' ForeColor="#0099CC" Font-Bold="true" Font-Size="Medium"></asp:Label>
</div>
<div id="div2" align="center">
<asp:TextBox ID="txt1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "SE_eventdetails")%>' Style="overflow: hidden;resize:none;" Height="30px" TextMode="MultiLine" Width="95%" MaxLength="100" BorderStyle="None" ></asp:TextBox>
</div>
<div id="div3" align="right" style="padding-right:5px;">
<asp:LinkButton ID="LinkButton1" runat="server">View more</asp:LinkButton>
</div>
</div>
<br />
</ItemTemplate>
<AlternatingItemStyle BackColor="White" />
<ItemStyle BackColor="#FFFBD6" ForeColor="#333333"/>
<SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
</asp:DataList>
<div id="div4" align="right">
<asp:LinkButton ID="btn_prev" runat="server" onclick="btn_prev_Click">Prev</asp:LinkButton>
<asp:LinkButton ID="btn_first" runat="server" onclick="btn_first_Click">First</asp:LinkButton>
<asp:LinkButton ID="btn_nxt" runat="server" onclick="btn_nxt_Click">Next</asp:LinkButton>
<asp:LinkButton ID="btn_last" runat="server" onclick="btn_last_Click">Last</asp:LinkButton>
</div>
</div>
..............................................................................
this is how your Design page looks:
................................................
and your code file should contain this:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class check : System.Web.UI.Page
{
decimal count; //for count the total records.
Decimal last1; // to access the last record
String fn; // for image name
String pth; // for storing the path
string connstr = ConfigurationManager.ConnectionStrings["your connection string"].ConnectionString;
SqlCommand cmd;
PagedDataSource pageData = new PagedDataSource();
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connstr);
con.Open();
doPaging();
}
public DataTable getTheData()
{
SqlConnection con = new SqlConnection(connstr);
con.Open();
SqlDataAdapter objSQLAdapter = new SqlDataAdapter("select SE_eventname,SE_eventdetails from Events", con);
DataSet DS = new DataSet();
objSQLAdapter.Fill(DS);
if (DS.Tables[0].Rows.Count == 0)
{
//lbl_msg.Text = "";
DataList1.Visible = false;
}
else
{
Session["cnt"] = DS.Tables[0].Rows.Count;
}
return DS.Tables[0];
}
private void doPaging()
{
//paging function
try
{
pageData.DataSource = getTheData().DefaultView; //will call the getTheData() method
pageData.AllowPaging = true;
pageData.PageSize = 2;
count = Convert.ToInt32(Session["cnt"]);
last1 = count / pageData.PageSize;
last1 = Convert.ToDecimal(Math.Ceiling(last1)); // will convert the 17/4 = 4.5 –> 5 pages
try
{
pageData.CurrentPageIndex = Int32.Parse(Request["page"].ToString());
}
catch
{
pageData.CurrentPageIndex = 0; // default first 4 images
}
btn_prev.Visible = (!pageData.IsFirstPage);
btn_first.Visible = (!pageData.IsFirstPage);
btn_nxt.Visible = (!pageData.IsLastPage);
btn_last.Visible = (!pageData.IsLastPage);
DataList1.DataSource = pageData;
DataList1.DataBind();
}
catch
{
}
}
protected void btn_prev_Click(object sender, EventArgs e)
{
Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pageData.CurrentPageIndex -1).ToString());
}
protected void btn_first_Click(object sender, EventArgs e)
{
Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pageData.CurrentPageIndex == 1).ToString());
}
protected void btn_nxt_Click(object sender, EventArgs e)
{
Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pageData.CurrentPageIndex + 1).ToString());
}
protected void btn_last_Click(object sender, EventArgs e)
{
Response.Redirect("check.aspx?page=" + Convert.ToInt32(last1 - 1)); // dtlist.aspx to access the last record.
}
}
<asp:Label ID="error" runat="server" Text=""></asp:Label>
<div id="selector1" style="font-family:Tahoma;
font-size:15px;
font-weight:bold">
Events and Exhibitions
</div>
<div id="selector" align="center" >
<asp:DataList ID="DataList1" runat="server" Width="627px" >
<ItemTemplate>
<div id="selector2">
<div id="div1" style="padding-left:5px;">
<asp:Label ID="label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "SE_eventname")%>' ForeColor="#0099CC" Font-Bold="true" Font-Size="Medium"></asp:Label>
</div>
<div id="div2" align="center">
<asp:TextBox ID="txt1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "SE_eventdetails")%>' Style="overflow: hidden;resize:none;" Height="30px" TextMode="MultiLine" Width="95%" MaxLength="100" BorderStyle="None" ></asp:TextBox>
</div>
<div id="div3" align="right" style="padding-right:5px;">
<asp:LinkButton ID="LinkButton1" runat="server">View more</asp:LinkButton>
</div>
</div>
<br />
</ItemTemplate>
<AlternatingItemStyle BackColor="White" />
<ItemStyle BackColor="#FFFBD6" ForeColor="#333333"/>
<SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
</asp:DataList>
<div id="div4" align="right">
<asp:LinkButton ID="btn_prev" runat="server" onclick="btn_prev_Click">Prev</asp:LinkButton>
<asp:LinkButton ID="btn_first" runat="server" onclick="btn_first_Click">First</asp:LinkButton>
<asp:LinkButton ID="btn_nxt" runat="server" onclick="btn_nxt_Click">Next</asp:LinkButton>
<asp:LinkButton ID="btn_last" runat="server" onclick="btn_last_Click">Last</asp:LinkButton>
</div>
</div>
..............................................................................
this is how your Design page looks:
................................................
and your code file should contain this:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class check : System.Web.UI.Page
{
decimal count; //for count the total records.
Decimal last1; // to access the last record
String fn; // for image name
String pth; // for storing the path
string connstr = ConfigurationManager.ConnectionStrings["your connection string"].ConnectionString;
SqlCommand cmd;
PagedDataSource pageData = new PagedDataSource();
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connstr);
con.Open();
doPaging();
}
public DataTable getTheData()
{
SqlConnection con = new SqlConnection(connstr);
con.Open();
SqlDataAdapter objSQLAdapter = new SqlDataAdapter("select SE_eventname,SE_eventdetails from Events", con);
DataSet DS = new DataSet();
objSQLAdapter.Fill(DS);
if (DS.Tables[0].Rows.Count == 0)
{
//lbl_msg.Text = "";
DataList1.Visible = false;
}
else
{
Session["cnt"] = DS.Tables[0].Rows.Count;
}
return DS.Tables[0];
}
private void doPaging()
{
//paging function
try
{
pageData.DataSource = getTheData().DefaultView; //will call the getTheData() method
pageData.AllowPaging = true;
pageData.PageSize = 2;
count = Convert.ToInt32(Session["cnt"]);
last1 = count / pageData.PageSize;
last1 = Convert.ToDecimal(Math.Ceiling(last1)); // will convert the 17/4 = 4.5 –> 5 pages
try
{
pageData.CurrentPageIndex = Int32.Parse(Request["page"].ToString());
}
catch
{
pageData.CurrentPageIndex = 0; // default first 4 images
}
btn_prev.Visible = (!pageData.IsFirstPage);
btn_first.Visible = (!pageData.IsFirstPage);
btn_nxt.Visible = (!pageData.IsLastPage);
btn_last.Visible = (!pageData.IsLastPage);
DataList1.DataSource = pageData;
DataList1.DataBind();
}
catch
{
}
}
protected void btn_prev_Click(object sender, EventArgs e)
{
Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pageData.CurrentPageIndex -1).ToString());
}
protected void btn_first_Click(object sender, EventArgs e)
{
Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pageData.CurrentPageIndex == 1).ToString());
}
protected void btn_nxt_Click(object sender, EventArgs e)
{
Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pageData.CurrentPageIndex + 1).ToString());
}
protected void btn_last_Click(object sender, EventArgs e)
{
Response.Redirect("check.aspx?page=" + Convert.ToInt32(last1 - 1)); // dtlist.aspx to access the last record.
}
}
-------------------------------------------------------------------
and your final output is:
Thats it......! u r done with paging
No comments:
Post a Comment