473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Gridview bound with Code not allowing paging

Hello:

my problem resides on the following, off course I do dataBinding to a
gridview by a class created under Vs2005 c#.

I do databinding to my gridview smooth and works fine when i call the
method to databind to my gridview, but when I allowPaging = true by
code or by designer, and after calling the same method listed right
below, I get no data.
please see my code. Any help will be appreciated and shared with
anyone.

public Boolean gridViewDataBind(ref System.Web.UI.WebControls.GridView
myGv, string mySqlStr, string[] PkFields )
{
Boolean result = false;
if (mySqlConn.State != ConnectionState.Open)
getConnected();
try
{

SqlCommand sqlCommand = new SqlCommand(mySqlStr,
mySqlConn);
SqlDataReader dr = sqlCommand.ExecuteReader();

myGv.DataSource = dr;
myGv.DataKeyNames = PkFields; // PK field
myGv.DataBind();

myGv.AllowPaging = true;
myGv.PageSize = 10;

dr.Dispose();
sqlCommand.Dispose();
result = true;

}
catch { result = false; }
return result;

}

Apr 3 '07 #1
1 1153
Are you sure you're not throwing an exception somehow? It looks to me like
you're blindly swallowing your exceptions and returning the boolean False;
apart from being a bad idea to blindly swallow exceptions, that might be
your problem.

What happens if you remove the generic catch statement and just let the
function execute as-is (or place a debug break in your exception handler).

--
~~~~~~~~~~~
Ben Rush
http://www.ben-rush.net/blog
<je*****@gmail.comwrote in message
news:11**********************@e65g2000hsc.googlegr oups.com...
Hello:

my problem resides on the following, off course I do dataBinding to a
gridview by a class created under Vs2005 c#.

I do databinding to my gridview smooth and works fine when i call the
method to databind to my gridview, but when I allowPaging = true by
code or by designer, and after calling the same method listed right
below, I get no data.
please see my code. Any help will be appreciated and shared with
anyone.

public Boolean gridViewDataBind(ref System.Web.UI.WebControls.GridView
myGv, string mySqlStr, string[] PkFields )
{
Boolean result = false;
if (mySqlConn.State != ConnectionState.Open)
getConnected();
try
{

SqlCommand sqlCommand = new SqlCommand(mySqlStr,
mySqlConn);
SqlDataReader dr = sqlCommand.ExecuteReader();

myGv.DataSource = dr;
myGv.DataKeyNames = PkFields; // PK field
myGv.DataBind();

myGv.AllowPaging = true;
myGv.PageSize = 10;

dr.Dispose();
sqlCommand.Dispose();
result = true;

}
catch { result = false; }
return result;

}

Apr 3 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: | last post by:
Hello, I have a GridView in my ASP.NET 2.0 application that performs the paging feature perfect when I have it bound to a data source. But now I have it bound to a dataset and the paging...
5
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens...
6
by: Carlos Albert | last post by:
Hi everybody, I'm working with a gridview (4 bound columns and 1 template column, using databind from codebehind). It works just fine, but I tried to add paging, and when I click any paging...
4
by: Bishop | last post by:
I have a number of simple select queries that a user needs to be able to execute and display the data on the screen in a gridview. My thought was that I could use a Gridview set to dymanically...
3
by: mazdotnet | last post by:
Hi everyone, I know when you enable paging in a datagrid the entire data is read but only the data that you want is displayed to the end user. Has this changed for Gridview? So if you have 10000...
3
by: Mike P | last post by:
When I am performing a command on a row in my gridview, it works fine, unless I have paging enabled and I try t execute the command on a page other than the first page. The error I get is 'Index...
8
by: AG | last post by:
ASP.NET 2.0, VS 2005 I have a gridview with paging enabled, bound to an objectdatasource. Both were dropped on to the page and configured via the wizards. Basically working as expected. The...
2
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few...
1
by: John A Grandy | last post by:
In regard to a GridView that must support searching, filtering, sorting, and paging ... There is a tradeoff in performing the sorting and paging in the database versus to creating a CLR sort...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.