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!
Yeah, looks like that was my mistake. A way to accomplish that would be to get the index off of a column that you found by the key.
int index = this.WebDataGrid1.Columns["key"].Index;
GridRecordItem cell = this.WebDataGrid1.Behaviors.Selection.SelectedRows[0].Items[index];
regards,Dave
When I use row.Items to access rows on the server there is only a method constructor to enter a column index number - row.items[0]. It doesn't allow me to enter a key - row.Items["key"].
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.
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