in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

Single Row Selection in AspxGridView???

Last post 10/1/2007 10:54 PM by Mehul Harry (Developer Express). 5 replies.
Page 1 of 1 (6 items)
Sort Posts:
Previous Next
  • 9/28/2007 4:33 AM

    Single Row Selection in AspxGridView???

    Hi,

    I'm using the latest version of your product (7.2).
    I've been searching through the documentation for 2 days now and trying demystify the art around trying to force an end user to only make one selection on the AspxGridView control, as opposed to the default multi-row selection behaviour.
    I've tried using the client-side events, but this is somewhat tricky:

    I've hooked the RowClick ClientSide event to a JScript function as follows:

    function(s, e) {
     s.UnselectRows();
     s.SelectRows(e.visibleIndex);
    }

    The first line works fine, the second line throws a "Missing Primary Key Exception".
    To mitigate this, I've also set the KeyFieldName in both design time and also at run time.
    Even through all of this, I still can't seem to get this to work! Sad

    Please shed some wisdom on this subject?
    I've looked into the sample on the site regarding using Radio Buttons, but I don't want to make an unnecessary call to the server just because the user selected a row...
    When I use s.SelectRow(e.visibleIndex, true); I don't get an error, but it doesn't physically select the row either??? It just focuses the row...

    My code to bind the grid to a datasource is as follows:

    agvProperties.KeyFieldName =

    "PropertyID";
    agvProperties.DataSource = props;
    agvProperties.DataBind();
    "Success is directly proportional to effort."
  • 9/28/2007 7:33 AM In reply to

    Re: Single Row Selection in AspxGridView???

    Answer

    Hi Chris,

    Please take a look at the following tutorial. The client-side rowclick which calls OnRowClick should explain how:

    Enable one row selection in the grid with Radiobuttons

    Thanks. 

    Filed under:
  • 10/1/2007 2:47 AM In reply to

    Re: Single Row Selection in AspxGridView???

    Hi Mehul,

    Thanks for the reply - I had already seen that article and it helped me onto something similar.
    For future searches, this is what I'm doing now:
    I'm using the custom callback event which is called in the client side event handler for RowClick(s, e);

    On the server [grid_CustomCallback (object sender, EventArgs e);], I'm ensuring that the only selected row is the row that was clicked and this works ok.

    I didn't really want to use any server side processing for selecting grid rows, but I realised it's not so bad after all.

    Thanks again.

    Chris

    "Success is directly proportional to effort."
  • 10/1/2007 3:10 AM In reply to

    Re: Single Row Selection in AspxGridView???

    Hi Chris,

    Glad to hear you got it working. Btw, you can use clientside code as well. The previous tutorial calls this function from rowclick:

    function OnRowClick(e) {
    //Clear the text selection
    _aspxClearSelection();
    //Unselect all rows
    grid._selectAllRowsOnPage(false);
    //Select the row
    grid.SelectRow(e.visibleIndex, true);
    grid.PerformCallback(e.visibleIndex);
    }

    The last line you can omit if you don't need to do anything special on the serverside. This tutorial however remembers the selection across pages by storing it in a session variable.

    Thanks. 

    Filed under:
  • 10/1/2007 7:46 AM In reply to

    Re: Single Row Selection in AspxGridView???

    Hi Mehul,

    I tried that in the beginning. If you look at my original post, I mentioned that the method below isn't doing what it says... 
    //Select the row
    grid.SelectRow(e.visibleIndex, true);

    Above method focuses the row, but does not actually "select" it.
    As a result, I've had to use server-side processing for that.

    I think it's not selecting the row because it's doing an AJAX call anyway (even after omitting the grid.PerformCallback method)...

    That was actually the point - I wanted to actually force selection of one row only (een on the row click event) but it didn't actually "select" the row at all.

    Nonetheless, it's working for now - I can't afford to spend any more time on this since I'm running behind on my deadlines already.
    Again, thanks for your time and your feedback.

    Chris

    "Success is directly proportional to effort."
  • 10/1/2007 10:54 PM In reply to

    Re: Single Row Selection in AspxGridView???

    Hi Chris,

    Yes, you're correct and my apologies. I believe because the check box is not actually being clicked that the selection is not made. I experimented to see if another way is possible and there might be. But I agree with you that it's simple enough to just add the callback line which will select the row anyway.

    Thanks. 

     

    Filed under:
Page 1 of 1 (6 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED