Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
Select Row on Client Side Javascript
posted

Hello!

I would like to select the first row of a WebDataGrid upon load in javascript.  I am calling the following function in the 'SelectionClientEvents -> Initialize' event.

function SelectRow()
{
var grid = document.getElementById('<%=wdgASNList.ClientID%>');
var gridRow = grid.get_rows().get_row(0);
grid.get_behaviors().get_selection().get_selectedRows().add(gridRow);
}

I am receiving the "Object doesn't support this property or method" error at
var gridRow = grid.get_rows().get_row(0);

Perhaps I am doing something wrong! 

Thanks for all the help!

John

  • 2783
    Suggested Answer
    posted

    Hi,

    In order to do this, handler the Grid's Initialize event instead, when you try to do it in the Selection's Initialize event, the behavior has not finished initializing yet.  You can do this like so:

     <ig:WebDataGrid ID="WebDataGrid1" runat="server" Width="400px" Height="400px">   
     <Behaviors>   
      <ig:Selection RowSelectType="Multiple"> </ig:Selection>
     </Behaviors>
          
     <ClientEvents Initialize="GridInit" /> 
    </ig:WebDataGrid>

    function GridInit(grid, evntArgs)
    {
     var row = grid.get_rows().get_row(0);
     grid.get_behaviors().get_selection().get_selectedRows().add(row);
    }

    Thank You,

    Olga

  • 33839
    Verified Answer
    posted

    John,

    You need to find the grid as its JavaScript object, not just a DOM element in order to access its methods.  Additionally, trying to select the row in the Selection behavior's initialize event means selection isn't ready yet. You can do this in the grid's initialize event.


            function SelectRow() {
                var grid = $find("WebDataGrid1"); // my DataGrid has an Id of WebDataGrid1
                var gridRow = grid.get_rows().get_row(0);
                grid.get_behaviors().get_selection().get_selectedRows().add(gridRow);
            }


                 <ClientEvents Initialize="SelectRow" />

     

    regards,
    Dave Young