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
20
Get selected webgrid row
posted

I have a webgrid which gets data from a sqldatasource. On click of a button, I want to get the value of the cells in the selected row and do some processing with the values. Any example in C# would be very helpful.

Thanks,

Subhankar.

  • 2426
    posted

    One thing to keep in mind is that the UltraWebGrid can have multiple selected rows but only one ActiveRow. You can set the row selection to single in the designer or in the grid's InitializeLayout event like this:

    e.Layout.SelectTypeRowDefault = SelectType.Single;

    When you handle the button's click event, you can then select the cell collection off of the grid's selected row. Remember that SelectedRows is a collection and uses an integer indexer:

    var myVal = myGrid.DisplayLayout.SelectedRows[0].Cells.FromKey("ColumnName").Value;

    Using the ActiveRow works much the same way:

    var myVal = myGrid.DisplayLayout.ActiveRow.Cells.FromKey("ColumnName").Value;

     Hope that helps.

    -Aaron