Gridview bound with Code not allowing paging

Discussion in 'ASP .Net' started by jerrygp@gmail.com, Apr 3, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. Ben Rush Guest

    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


    <> wrote in message
    news:...
    > 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;
    >
    > }
    >
    Ben Rush, Apr 3, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    3,138
  2. sunil panda

    Lower bound & Upper bound

    sunil panda, Dec 25, 2003, in forum: Java
    Replies:
    9
    Views:
    7,232
    thushara wijeratna
    Oct 7, 2008
  3. Rhiner Dan
    Replies:
    1
    Views:
    742
    Mike Wahler
    Mar 27, 2005
  4. Mario Krsnic
    Replies:
    0
    Views:
    376
    Mario Krsnic
    Jun 23, 2006
  5. ES

    Paging In GridView bound to DataSet

    ES, Oct 4, 2006, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    296
Loading...

Share This Page