How do you retrieve data from a specific cell in a selected row? With the ultrawebgrid control, I used to do something like this:
e.Row.Cells.FromKey("ColumnName").Value
With the webdatagrid control, I saved all the selected rows in a SelectedRowCollection variable. How do I access the data, as I did above, for a specific cell in a row in that collection?
Thanks!
It depends upon whether you are accessing a cell on the client or server.
Assuming you have the row on the server- row.Items["key"] or row.Items[0] gives you a GridRecordItem
On the client, you can get a cell by index, column key, or column reference off a row as follows.
row.get_cell(0), row.get_cellByColumnKey("key"), row.get_cellByColumn(keyCol)
Off of the cell, you can get text by .Text on the server or .get_text() on the client.
regards,
David Young
Hi,
I have a similar need, I'm writing javascript to get the ID of the selected row (ID is the first column in my WebDataGrid).
Your examples above will help, once I figure out how to get the selected row from the WDG.
(the WDG is configured to only allow 1 row selected at a time)
Can you help?
Mike
Excellent! thanks.
I now have a button on my form that uses javascript to open a window based on the selected row in my WebDatGrid. Thanks!
Now, when I return focus to my original window, the WDG is empty (shows nothing)
anything I should/could do in js to ensure the grid (data) remains visible?
my button, and js are:
<asp:Button ID="OpenViewButton" Text="Open" width="80px" runat="server" OnClientClick="OpenHDWindow()" />
<script type="text/javascript">
function OpenHDWindow() {
var viewid = 0;
var grid = $find('<%= WebDataGrid1.ClientID %>');
if (grid == null) {
alert(
"Could not locate grid.");
return false;
}
var selectedRows = grid.get_behaviors().get_selection().get_selectedRows();
var row = selectedRows.getItem(0);
if (row == null) {
"no row selected");
var col = row.get_cell(0);
viewid = col.get_value();
var url = 'DashboardHD.aspx?vid=';
url += viewid;
// set up to open in new window
var params = "fullscreen=yes, scrollbars=no";
newwin = window.open(url,
'Hit F11 to Maximize', params);
if (window.focus) { newwin.focus() }
</script>
Mike,
This should be fairly simple to accomplish what you need.
To get the selected rows collection on the client, do the following
var grid = $find("GridId");
var firstRow = selectedRows.getItem(0);
From there, you should be able to follow the code in my other post. If you need to know how to get a column, you can do grid.get_columns().get_column(0), grid.get_columns().get_columnByKey("firstKey")
This should get you rolling. Let us know if you need further help.