C# .NET - Gridview - Asked By Ramendra Kumar on 18-Jan-10 01:04 AM

hi i want to fetch the maximum rows in the gridview,

re - Santhosh N replied to Ramendra Kumar on 18-Jan-10 01:08 AM

If you want to get the number of rows in thr gridview then you can get that using

gridView1.Rows.Count


re - fetch the maximum rows in the gridview - DL M replied to Ramendra Kumar on 18-Jan-10 01:24 AM

Try this code sample to get number of row in GV and display in label


int intStartRecord = (GridView1.PageIndex * GridView1.PageSize) + 1;
int intEndRecord = (GridView1.PageIndex * GridView1.PageCount) + 1 + GridView1.Rows.Count;
int intCurrentPage = GridView1.PageIndex + 1;
int intTotalRecords = YourDataSource.Rows.Count;


lblDisplaying.Text = "Displaying records " + intStartRecord.ToString() + " through " + intEndRecord.ToString() + " of " + intTotalRecords.ToString() + " items found (page " + intCurrentPage.ToString() + " of " + GridView1.PageCount.ToString() + ")!";

another way you can achieve this using dataset

protected void ObjectDataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs e)
    {
                          
                                   
        int RecordsCount = ((DataSet)e.ReturnValue).Tables[0].Rows.Count;

  }  

re - fetch the maximum rows in the gridview - DL M replied to Ramendra Kumar on 18-Jan-10 01:30 AM

you can do using javascript also

<script type="text/javascript">

        ///<summary>Method for Web Service Failed Event</summary>

        ///<param name="error">Error Object</param>

        ///<returns>false</returns>

        function onFailedWS(error)

        {

         alert(error.get_message());

        }

   

        ///<summary>This is the callback function that processes the Web Service return value.</summary>

        ///<param name="result">result Object from Web Service</param>

        function SucceededCallback(result)

        {

            //get the div element

            var RsltElem = $get("testDiv");

            //update div inner Html

            RsltElem.innerHTML =result;

            //format table inside the div

            //if you have multiple table call format table in loop

            formatTable(RsltElem.getElementsByTagName('table')[0].id)

        }

   

        ///<summary>This function calls the GetControlHtml Web Service method.</summary>

        ///<param name="error">Succeed Object</param>

        ///<param name="error">Error Object</param>

        function getData(controlLocation)

        {

                ScriptService.GetControlHtml(controlLocation, SucceededCallback, onFailedWS);

        }

       

        function formatTable(gvID){

            //get the gridview

            var gv = $get(gvID);

            //get numbers of column in grid view

            cols = gv.rows[0].cells.length - 1;

            //get numbers of rows in grid view

            rows = gv.rows.length -1;

            //intialized looping variables

            var i=0;

            var j=0;

            //loop for each row in gridview

            for(i=1;i<rows;i++){

                //attach mouseover event for row

                $addHandler(gv.rows[i], "mouseover", mouseOver);

                //attach mouseout event for row

                $addHandler(gv.rows[i], "mouseout", mouseOut);

                //attach click event for row

                $addHandler(gv.rows[i], "click", onClick);

                 //loop for each cell in row

                for(j=0;j<cols;j++){

                        //set tooltip for cells in row

                    setTitle(gv.rows[i].cells[j]);                        

                }

            }   

        }

        function setTitle(object){

            //check browser type

            if(Sys.Browser.name =="Firefox"){

            object.title = object.textContent;

            }

            else{

            object.title = object.innerText;

            }

        }

       

        function mouseOver(objectEvent){

            //is row already clicked

            if(! isClickedStyleSet(objectEvent.target.parentNode.className))

            {

            //set class name

            objectEvent.target.parentNode.className = "row-over" ;

            //check browser type

             if(Sys.Browser.name !="Firefox"){

                objectEvent.target.parentNode.style.cursor ="hand";

            }}

        }

        function mouseOut(objectEvent){

            //is row already clicked

            if(! isClickedStyleSet(objectEvent.target.parentNode.className)){

            //set class name

            objectEvent.target.parentNode.className = "data-row" ;

        }}

        function onClick(objectEvent){

            //set class name

            if(! isClickedStyleSet(objectEvent.target.parentNode.className))

            {

                objectEvent.target.parentNode.className = "row-select" ;

            }

            else

            {

                objectEvent.target.parentNode.className = "data-row" ;

            }

        }

        function isClickedStyleSet(className){

            //if row is already clicked return true

            if(className == "row-select"){

            return true;

            }

            return false;

        }

    </script>

http://weblogs.asp.net/sanjeevagarwal/archive/2008/07/22/Dynamically-create-ASP.NET-user-control-using-ASP.NET-Ajax-and-Web-Service.aspx
maximum rows in the gridview - mv ark replied to Ramendra Kumar on 18-Jan-10 03:11 AM
By implementing Continuous Scrolling UI Pattern in ASP.NET utilizing AJAX, you can display voluminous data (especially read only data) while providing a better user experience & also making efficient use of server bandwidth - http://www.eggheadcafe.com/tutorials/aspnet/b8381915-06d9-4538-b4bb-5ac2a8e73f34/implementing-continuous-s.aspx

When using pagination patterns, a decision to only show a subset of data at a time and then let the user request more data if wanted is chosen. With the Continuous Scrolling, new data is automatically retrieved as the user has scrolled to the bottom of the page. It thus appears as if the page has no end, as more data will be loaded and inserted into the page each time the user scrolls to the bottom of page.