I'm using the 11.2 ASP controls in VS2010 using the WebHierarchicalDataGrid control
I'm doing everything on the server side. I have a column with a button that is wired up to a click event. When I click the button I execute some SQL that updates a value in the current row.
How do I get the updated value to show up in the current row?
Seems like I should be able to tell the grid to do a refresh on the current row.
Thanks.
Brian.
Hello Brian,
Thank you for posting in our community. You need to rebind again the grid. Clear the data source of the GridView assign the updated data source.
I hope this helps.
For any further questions do not hesitate to contact me.
Sincerely,
Georgi Sashev
Developer Support Engineer
Infragistics, Inc.
http://ko.infragistics.com/support
Georgi,
I tried your suggestion. After executing the SQL update I call this code in the button click event.
WebHierarchicalDataGrid1.GridView.ClearDataSource();
WebHierarchicalDataGrid1.DataSourceID = "WebHierarchicalDataSource1";
However, this causes the second band I'm on to collapse and the user loses where they were in the hierarchy.
The closest thing I've been able to do is place the WebHierarchicalDataGrid into a UpdatePanel, then after the SQL update I set the text in the row to what I know the SQL update would do. Plus, I disable the button. But, this has some undesired side effects when the grid resorts.
I'm thinking that a better solution would be to programmatically set the values in the row instead of via the SQL update command. Would this be a better solution? If so, how can I set the value for the row in the click event?
Thanks,
Here is a sample with WHDG batch updating. You can review it and let me know if this approach works for you in this case:
http://samples.infragistics.com/aspnet/Samples/WebHierarchicalDataGrid/EditAndSelection/BatchUpdating/Default.aspx?cn=hierarchical-data-grid&sid=29a3e22c-ccc7-4214-a7bb-006c13c7b0ea
I read the batch update info, I'm not seeing how batch updating will help. I want to update the grid via some code and not via having the user type in something. I'm not seeing a way to change the value in a cell via code after the button click, is there a way?
Let me tell you more about my problem...
In the second band of a WebHierarchicalDataGrid I have a column with a button, when I click the button I want to do a calculation and change the value in another column of the same row with the result of my calculation, and then I want the changed value to show up in the grid and the database.
I get the impression that the best way to do this is to programmatically change the value on the client side via some javascript, correct?
This would allow the grid and database to both reflect the change??
Is this the best approach for my situation?
Is there another way to solve this problem?
So, if this is correct....
I've wired up a button click event and I can get the gridView on the client side using javascript.
However, now I can't get the cell or row I just clicked on. The .get_ActiveCell() is always null.
How can I get the cell / row I just clicked the button in?
We have decided to skip the feature for now. I'll let you know if we get back to it and need help to resolve it.
Can you update me with your progress on this case?
If you have any questions do not hesitate to contact me.
Can you provide me with a sample that reproduces this in order for me to investigate it further and assist you in finding a solution.
Looking forward to hear from you.
Georgi ,
Thanks for the reply and sample code.
However, in my case the solution is much simpler.
I was told I needed to use this code...
var activeCell = parentGrid.get_behaviors().get_activation().get_activeCellResolved();
Now I can get to the active cell for the row the button was clicked in.
I think your code would find the active cell if the button I clicked on was outside the grid.
However, the one problem I now have is that I cannot set the value of the active cell.
The column in my grid is a template that contains a button, the column is a boolean and tied to the enabled property of the button. This seems to work fine. But, when I try to set the value of the cell in the javascript the button disapears.
The code I'm using is...
activeCell.set_value(false);
This causes the button to disapear and the text "false" to show up in it's place.
I think the issue has to do with the fact I'm using a template for this cell.
Any suggestions on how to correctly set the value when using a template?
It is possible the ActiveCell to be null if you are trying to retrieve the activeCell of the child band. Here I will show you what function I created.
function btnOne_Click() { var grid = $find("WebHierarchicalDataGrid1"); var parentGrid = grid.get_gridView(); var childGrid; var text; var activeCell; if (grid != null) { activeCell = parentGrid.get_behaviors().get_activation().get_activeCell(); if (activeCell != null) { text = activeCell.get_text(); } else { for (i = 0; i < grid.get_gridView().get_rows().get_length(); i++) { if (grid.get_gridView().get_rows().get_row(i).get_expanded()) { var childGrid = grid.get_gridView().get_rows().get_row(i).get_rowIslands(0)[0]; if (childGrid != null) { activeCell = childGrid.get_behaviors().get_activation().get_activeCell(); if (activeCell != null) text = activeCell.get_text(); } } } } if (text != null) alert(text); } }
function btnOne_Click() {
var grid = $find("WebHierarchicalDataGrid1");
var parentGrid = grid.get_gridView();
var childGrid;
var text;
var activeCell;
if (grid != null) {
activeCell = parentGrid.get_behaviors().get_activation().get_activeCell();
if (activeCell != null) {
text = activeCell.get_text();
}
else
{
for (i = 0; i < grid.get_gridView().get_rows().get_length(); i++) {
if (grid.get_gridView().get_rows().get_row(i).get_expanded())
var childGrid = grid.get_gridView().get_rows().get_row(i).get_rowIslands(0)[0];
if (childGrid != null) {
activeCell = childGrid.get_behaviors().get_activation().get_activeCell();
if (activeCell != null) text = activeCell.get_text();
if (text != null) alert(text);
Add this button to the page
<input type="button" id="btnOne" value="active cell" onclick="return btnOne_Click();"/>
This function will display the value of the active cell. Try it and let me know if it works for you. Or if you have any further questions