C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






ASP.NET DataList control with Next and Previous Buttons


Posted Date: 07 Jun 2008    Resource Type: Code Snippets    Category: Databinding

Posted By: Raju.M       Member Level: Gold
Rating:     Points: 5



The code snippet is an example that uses an ASP.NET DataList Control with Next And Previous Buttons. The buttons help users to navigate records.

DBHelper is a class that connects to the Database. PagedDataSource is used to add paging for DataList.PageCount is obtained from ViewState.



DBHelper objDBHelper;
PagedDataSource pgddata;
public int PageCount
{
get
{
object o = this.ViewState["_PageCount"];
if (o == null)
return 0;
else
return (int)o;
}
set
{
ViewState["_PageCount"] = value;
}
}

protected void Page_Load(object sender, EventArgs e)
{
objDBHelper = new DBHelper();
if (!IsPostBack)
{
FillDataList(true);
}
else
{
FillDataList(false);
}
}

public void FillDataList(bool a)
{
if (a)
PageCount = 0;
lbtnNext.Enabled = true;
lbtnNext2.Enabled = true;
lbtnPrevious.Enabled = true;
lbtnPrevious2.Enabled = true;

string cmd = string.Format("SELECT a, c,b,d,e,f,g,h FROM table WHERE z >'{0}'", DateTime.Now);
DataTable BTab = objDBHelper.GetReaderTable(cmd, 7);
if (BTab.Rows.Count > 0)
{
if (a)
PageCount = 0;
lbtnNext.Enabled = true;
lbtnNext2.Enabled = true;
lbtnPrevious.Enabled = true;
lbtnPrevious2.Enabled = true;


DataColumn newcolm = new DataColumn("name", typeof(string));
DataColumn newcolm1 = new DataColumn("bookme", typeof(string));
DataColumn calCol=new DataColumn ("viewcal",typeof(string));


BTab.Columns.Add(newcolm);
BTab.Columns.Add(newcolm1);
BTab.Columns.Add(calCol);

for (int i = 0; i < BTab.Rows.Count; i++)
{
BTab.Rows[i]["name"] = (object)objDBHelper.ExecuteScalar(string.Format("SELECT a FROM table WHERE d='{0}'", BTab.Rows[i][1].ToString()));
BTab.Rows[i]["bookme"] = string.Format("page.aspx?xy={0}&gud={1}", BTab.Rows[i][0].ToString(), BTab.Rows[i][1].ToString());
BTab.Rows[i]["viewcal"] = string.Format("page2.aspx?pd={0}&zid={1}", BTab.Rows[i][1].ToString(), BTab.Rows[i][0].ToString());
}
pgddata = new PagedDataSource();
pgddata.DataSource = BTab.DefaultView;
pgddata.AllowPaging = true;
pgddata.CurrentPageIndex = PageCount;
pgddata.PageSize = 5;
lbtnPrevious2.Visible = !pgddata.IsFirstPage;
lbtnPrevious.Visible = !pgddata.IsFirstPage;
lbtnNext2.Visible = !pgddata.IsLastPage;
lbtnNext.Visible = !pgddata.IsLastPage;
dlClubList.DataSource = pgddata;
dlClubList.DataBind();
}
}
protected void lbtnPrevious_Click(object sender, EventArgs e)
{
PageCount -= 1;
FillDataList(false);
}
protected void lbtnNext_Click(object sender, EventArgs e)
{
PageCount += 1;
FillDataList(false);
}


			



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Using ASP.NET DataList control  .  Navigating records with Next and Previous buttons  .  Navigating records in DataList control  .  ASP.NET DataList Control with Next And Previous  .  ASP.NET DataList control  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to Get newly added row in dataset
Previous Resource: filter table at runtime from dataset and store it in datatable in c#
Return to Discussion Resource Index
Post New Resource
Category: Databinding


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use