C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

Datalist Paged Data Source example ASP.Net with C#


Posted Date: 26 Sep 2008      Posted By: manivannan      Member Level: Silver     Points: 1   Responses: 1



Datalist Paged Data Source example ASP.Net with C#




Responses

Author: Aamir    28 Sep 2008Member Level: BronzeRating: 2 out of 52 out of 5     Points: 6

Try this code
for code behind
string connectionString = @"Data Source=l-msaam-jlg6t1s\sqlexpress;Integrated Security=True;Initial Catalog=Northwind";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
intPageSize.Text = "4";
intCurrIndex.Text = "0";
DataBind();
}
}

private void DataBind()
{
SqlDataAdapter da = new SqlDataAdapter("Select orderid,customerid from orders",connectionString);
DataSet ds = new DataSet();

if (!Page.IsPostBack)
{
da.Fill(ds);
intRecordCount.Text = ds.Tables[0].Rows.Count.ToString(); ;
ds = null;
ds = new DataSet();
}
da.Fill(ds, int.Parse(intCurrIndex.Text), int.Parse(intPageSize.Text), "Orders");
dList.DataSource = ds.Tables[0].DefaultView;
dList.DataBind();


}
protected void prevbutton_Click(object sender, EventArgs e)
{
intCurrIndex.Text = Convert.ToString((int.Parse(intCurrIndex.Text) - int.Parse(intPageSize.Text)));

if (int.Parse(intCurrIndex.Text) < 0)
{
intCurrIndex.Text = "0";
}
DataBind();

}
protected void nextButton_Click(object sender, EventArgs e)
{
if (int.Parse(intCurrIndex.Text) + 1 < int.Parse(intRecordCount.Text))
{
intCurrIndex.Text = Convert.ToString((int.Parse(intCurrIndex.Text) + int.Parse(intPageSize.Text)));
}
if (int.Parse(intCurrIndex.Text) >= int.Parse(intRecordCount.Text))
{
intCurrIndex.Text = Convert.ToString(int.Parse(intCurrIndex.Text) - int.Parse(intPageSize.Text));
}

DataBind();
}


// For aspx page HTML


<div>
<asp:DataList ID="dList" Runat="server" Width="560px" ItemStyle-BackColor="Beige" EnableViewState="False">
<HeaderTemplate>
<table width="100%" style="font: 10pt verdana" cellpadding="0" cellspacing="0">
<tr style="background-color:FF0000">
<th align="left">
<font color="#FFFFFF">Customer ID</font></th>
<th align="left">
<font color="#FFFFFF">Order ID</font></th>
<th align="left">
<font color="#FFFFFF">Customer ID</font></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:#f5f5dc">
<td><%# DataBinder.Eval(Container.DataItem, "customerid")%></td>
<td><%# DataBinder.Eval(Container.DataItem, "orderid") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "customerid")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
<asp:Button id="prevbutton" runat="server" Text="Prev" OnClick="prevbutton_Click"></asp:Button>
<asp:Button id="nextButton" runat="server" Text="Next" OnClick="nextButton_Click"></asp:Button>
<asp:label ID="intCurrIndex" Visible="False" Runat="server" />
<asp:label ID="intPageSize" Visible="False" Runat="server" />
<asp:label ID="intRecordCount" Visible="False" Runat="server" />
</div>



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : i want aspx to pdf convertion c# coding with dll files also
Previous : search within Dataset and Bind it GridView in C#
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use