Skip to content

Get selected row on button click

New Discussion
Kelly
Kelly asked on May 30, 2012 11:58 AM

How do I get the selected row on the WebDataGrid on a button click, client side?

Sign In to post a reply

Replies

  • 0
    [Infragistics] Nikolay
    [Infragistics] Nikolay answered on Feb 17, 2012 1:18 PM

    Hi khoke,

    You could do this using javascript code, similar to the following:

            function buttonClicked() {

                var grid = $find("WebDataGrid1");

                //Gets the selected row

                var selectedRow = grid.get_behaviors().get_selection().get_selectedRows(0);

                //Gets the text from the first cell of the selected row

                var firstCell = selectedRow.getItem(0).get_cell(0).get_text();

                alert(firstCell);

            }

    If you have any further questions, please feel free to contact me.

     

     

    • 0
      [Infragistics] Nikolay
      [Infragistics] Nikolay answered on Feb 23, 2012 6:20 AM

      Hello khoke,

      Please let me know if you have any further questions.

      • 0
        Rob
        Rob answered on May 29, 2012 10:33 PM

        How can I get the selected row on the server side?

        i need to click a link button in one of the columns, and on the server side i need to get the exact row that i clicked on and calculate some things on the server, then set the row to be selected.

      • 0
        [Infragistics] Nikolay
        [Infragistics] Nikolay answered on May 30, 2012 7:32 AM

        Hi wvusaf,

        You could get the selected row, using the following syntax –  WebDataGrid1.Behaviors.Selection.SelectedRows[0]. When Selection behavior is enabled, on click of a templated button, the row which contains this button is already in the SelectedRows collection, so you should be able to access it with the same code.

        Please let me know if you have any further questions.

      • 0
        Rob
        Rob answered on May 30, 2012 11:58 AM

        The problem was that when the postback occurred by clicking on the LinkButton, the row wasn't selected.  i have a need to only allow the user to click in one specific column, ie the LinkButton column, to select the row.  So I set the RowSelectType to None, otherwise, any column the clicked in would select the row.

        What i ended up doing was this:

         

        this.WebDataGrid1.Behaviors.Selection.SelectedRows.Clear();

        foreach (Infragistics.Web.UI.GridControls.GridRecord row in this.WebDataGrid1.Rows)

        {

          if (row.Items[0].FindControl("LinkButton1").Equals(sender))

          this.WebDataGrid1.Behaviors.Selection.SelectedRows.Add(row);

        }

        This way, the behavior of the LinkButton column mimics the behavior of the ASP.NET GridView's Command Field, which has a 'Select' button.

        if there's a better way of acheiving what I've done please let me know.

        thanks

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Kelly
Favorites
0
Replies
5
Created On
May 30, 2012
Last Post
13 years, 9 months ago

Suggested Discussions

Created by

Created on

May 30, 2012 11:58 AM

Last activity on

Feb 19, 2026 9:39 PM