Need some advice on a GridView control.

Discussion in 'ASP .Net Web Controls' started by Midway, Aug 28, 2006.

  1. Midway

    Midway Guest

    Hi there,

    I am having this problem with a gridview control. what I'm doing is
    assigning the gridview's datasource to a objectdatasource which calls a
    parameterized stored procedure and that is all fine.

    I need to enable the paging and sorting on this gridview, so I have
    AllowSorting = True and AllowPaging = True on the gridview properties.

    I know since this gridview data source is being bound programatically, I
    need to handle the onSorting and PageIndexChanged.

    I have been searching the net a lot on how to handle this two but I'm not
    having having any luck on it.

    Can anybody out there guide to the right information and even give me some
    sample code that I could laverage on?

    Thanks very much in advance for your help.

    Manny
     
    Midway, Aug 28, 2006
    #1
    1. Advertising

  2. Midway

    Mikeon Guest

    > I am having this problem with a gridview control. what I'm doing is
    > assigning the gridview's datasource to a objectdatasource which calls a
    > parameterized stored procedure and that is all fine.
    >
    > I need to enable the paging and sorting on this gridview, so I have
    > AllowSorting = True and AllowPaging = True on the gridview properties.
    >
    > I know since this gridview data source is being bound programatically, I
    > need to handle the onSorting and PageIndexChanged.


    If you are using ObjectDataSource, why are you using the DataSource
    property and not the DataSourceId property? Using the later, frees you
    from having to handle the two events you have mentioned. You just have
    to provide methods with right parameters (i.e.: startindex, pagesize
    and sort expression) depending on the functionallity you want to get.
    Be sure also to check my controls pack at (and related articles on
    problems with ObjectDataSource):

    http://vaultofthoughts.net/ASPNETControlsPack.aspx

    If for some reason you are bound to using the DataSource property
    programatically, I'm sure there are a lot of articles on handlig paging
    and sorting as for example here:

    http://www.c-sharpcorner.com/Code/2003/Dec/PagingInASPNet.asp

    --
    Michal
    http://vaultofthoughts.net
     
    Mikeon, Aug 28, 2006
    #2
    1. Advertising

  3. Midway

    Midway Guest

    Hi there,

    Thanks for your reply. I'm kind of new to this kind of development but this
    is what I'm trying to do;

    the user will choose a item from a dropdown list and depending on the option
    the datasource should call a different store procedure depending on the
    parametern (i.e. if user chooses to search the field LastName, datasource
    should call a stored procedure that expects a parameter @LastName, that is
    going to be supplied through a text box, if the user chooses to search on the
    firstname, datasource should call a stored procedure that expects a parameter
    @FirstName, that will be supplied through a text box, and so on and so on)

    One way of doing this I think is changing the stored procedure name
    programatically depending on what the user decides to search on.

    Some ideas on how to accomplish this please!!???

    Thanks very much,

    Manny



    "Mikeon" wrote:

    > > I am having this problem with a gridview control. what I'm doing is
    > > assigning the gridview's datasource to a objectdatasource which calls a
    > > parameterized stored procedure and that is all fine.
    > >
    > > I need to enable the paging and sorting on this gridview, so I have
    > > AllowSorting = True and AllowPaging = True on the gridview properties.
    > >
    > > I know since this gridview data source is being bound programatically, I
    > > need to handle the onSorting and PageIndexChanged.

    >
    > If you are using ObjectDataSource, why are you using the DataSource
    > property and not the DataSourceId property? Using the later, frees you
    > from having to handle the two events you have mentioned. You just have
    > to provide methods with right parameters (i.e.: startindex, pagesize
    > and sort expression) depending on the functionallity you want to get.
    > Be sure also to check my controls pack at (and related articles on
    > problems with ObjectDataSource):
    >
    > http://vaultofthoughts.net/ASPNETControlsPack.aspx
    >
    > If for some reason you are bound to using the DataSource property
    > programatically, I'm sure there are a lot of articles on handlig paging
    > and sorting as for example here:
    >
    > http://www.c-sharpcorner.com/Code/2003/Dec/PagingInASPNet.asp
    >
    > --
    > Michal
    > http://vaultofthoughts.net
    >
    >
     
    Midway, Aug 28, 2006
    #3
  4. Midway

    Mikeon Guest

    > the user will choose a item from a dropdown list and depending on the option
    > the datasource should call a different store procedure depending on the
    > parametern (i.e. if user chooses to search the field LastName, datasource
    > should call a stored procedure that expects a parameter @LastName, that is
    > going to be supplied through a text box, if the user chooses to search on the
    > firstname, datasource should call a stored procedure that expects a parameter
    > @FirstName, that will be supplied through a text box, and so on and so on)
    >
    > One way of doing this I think is changing the stored procedure name
    > programatically depending on what the user decides to search on.
    >
    > Some ideas on how to accomplish this please!!???


    What about having one stored procedure that accepts all parameters with
    some default values?
    Than in a select statement you would write something like WHERE
    (FirstName = @FirstName OR @FirstName IS NULL)

    BTW: If your datasource control is just a layer between your database
    and the webform, maybe you should consider using SqlDataSource?


    --
    Michal
    http://vaultofthoughts.net
     
    Mikeon, Aug 29, 2006
    #4
    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. Ric

    Need some advice

    Ric, Jul 22, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    329
  2. =?Utf-8?B?Sm9l?=
    Replies:
    1
    Views:
    1,722
    Karl Seguin
    Jan 28, 2005
  3. Mike L.
    Replies:
    6
    Views:
    347
    Alan Silver
    Feb 6, 2005
  4. Shapper

    Need Some Advice.

    Shapper, Mar 13, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    360
    Karl Seguin
    Mar 13, 2005
  5. yuyazhang
    Replies:
    14
    Views:
    717
    yuyazhang
    Apr 29, 2006
Loading...

Share This Page