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 !






Custom Paging using Object Data Source


Posted Date: 15 Oct 2008    Resource Type: Code Snippets    Category: ASP.NET GridView

Posted By: Kapil Dhawan       Member Level: Gold
Rating:     Points: 5




Custom Paging using Object Data Source

<table width="100%">
<tr>
<td>
<GridView ID="grdUpdates" runat="server" Width="100%" AutoGenerateColumns="false"
DataKeyNames="id" AllowPaging="true" DataSourceID="srcFiling" PageSize="10" PagerStyle-HorizontalAlign="Center"
BackColor="#DCE1EC" RowStyle-Font-Names="verdana" RowStyle-Font-Size="11px" BorderStyle="Solid"
BorderWidth="2px">
</GridView>

//
</td>
</tr>
<tr>
<td>
//
ObjectDataSource ID="srcFiling" TypeName="PagingClass" SelectMethod="GetFiling"
SelectCountMethod="GetFilingCount" EnablePaging="True" runat="server"
//
</td>
</tr>
</table>




//
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Web.Configuration;

public class PagingClass
{
public static string _conString = WebConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
public static SqlDataReader GetFiling(int startRowIndex, int maximumRows)
{
// Initialize connection
SqlConnection con = new SqlConnection(_conString);
// Initialize command
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "GetFiles";
cmd.CommandType = CommandType.StoredProcedure;
// Add ADO.NET parameters
cmd.Parameters.AddWithValue("@StartRowIndex", startRowIndex);
cmd.Parameters.AddWithValue("@MaximumRows", maximumRows);
// Execute command
con.Open();
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
public static int GetFilingCount()
{
HttpContext context = HttpContext.Current;
if (context.Cache["FilingCount"] == null)
context.Cache["FilingCount"] = GetFilingCountFromDB();
return (int)context.Cache["FilingCount"];
}
private static int GetFilingCountFromDB()
{
int result = 0;
// Initialize connection
SqlConnection con = new SqlConnection(_conString);
// Initialize command
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT Count(*) FROM view_ownership";
// Execute command
using (con)
{
con.Open();
result = (int)cmd.ExecuteScalar();
}
return result;
}

}

//









//
ALTER PROCEDURE dbo.GetFiles
(
@StartRowIndex INT,
@MaximumRows INT
)
AS
-- Create a temp table to store the select results
CREATE TABLE #PageIndex
(
IndexId INT IDENTITY (1, 1) NOT NULL,
RecordId INT
)
-- INSERT into the temp table
INSERT INTO #PageIndex (RecordId)
SELECT Id FROM view_ownership
-- Get a page of movies
SELECT
Id,
shareholder,
secfileno,
formtypeId,
fileddate,
filedbyId,
cusip,
Issuername,
formtype,cik,flag
FROM
view_ownership
INNER JOIN #PageIndex WITH (nolock)
ON view_ownership.Id = #PageIndex.RecordId
WHERE
#PageIndex.IndexID > @startRowIndex
AND #PageIndex.IndexID < (@startRowIndex + @maximumRows + 1)
ORDER BY
view_ownership.fileddate desc
--#PageIndex.IndexID

//









Responses


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

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Custom Paging using Object Data Source  .  

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 a seelcted row from gridview on button click uisng row command event in c#
Previous Resource: Custom validators : Make easy and Simple Client Validation
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET GridView


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

it help desk

Contact Us    Privacy Policy    Terms Of Use