How do I get the selected row on the WebDataGrid on a button click, client side?
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.
Hello khoke,
Please let me know if you have any further questions.
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
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.
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.