Gridview bound with Code not allowing paging

J

jerrygp

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;

}
 
B

Ben Rush

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top