I have a TreeList with five columns. All of the data is read-only except for certain fields in the second column that the user can modify. When the user makes any changes in the second column (on keypress), I need to immediately (i.e. client-side) delete all the values in the fourth and fifth columns, and also reset the cell shading in those columns to their default colors. A coworker of mine was able to write a JQuery/Javascript function that accomplishes this nicely. However, whenever you expand a node somewhere else in the TreeList, then the fourth and fifth columns are restored to their previous values and cell shading -- which is obviously not what we want. These columns should not be updated until the user clicks a separate Calculate button outside of the TreeList that initiates a full postback. All the values are calculated server-side. The idea is that the data in the fourth and fifth columns is no longer valid if the user makes any changes, and so it should be deleted until the user recalculates. Our TreeList is bound to a datatable on the server side.
I basically have two questions:
- Is there a preferred way, using some internal events or other built-in capability of the TreeList, to accomplish the clearing and re-shading of these two columns?
- Can we prevent the TreeList from restoring the values that we erased (client-side) whenever a node is expanded?
Thanks.
Hi Ken,
This behavior is by design. The ASPxTreeList is a server-side control, and, thus, every action such as node expanding or sorting results in a callback to the server. The ASPxTreeList is rendered on the server, and then, the resulting html is sent to the client. Obviously, the changes performed on the client side are overridden by the callback result. A possible solution is to preserve the information about cleared nodes in a hidden field and then use the TreeList's HtmlDataCellPrepared event to clear the e.Cell.Text property.
Thanks,
Plato
Well, I got it working by clearing the client-side and then clearing the server-side data the next time it posts back. Everything works perfectly in IE, but in Firefox and Safari, it seems that the number of <td> cells rendered for each node in the treeview changes after the initial load. For example, in a particular 1st-level node, I might have five td cells when the page is originally loaded, but then it will have seven upon postback. I'm not talking about the extra td's that are created to the left of the row when the node is expanded. It just seems to add a couple of columns in the HTML, or at least in the Javascript/JQuery object model, and this causes the wrong columns to be affected. Is there something I should know that might be causing this behavior only in Firefox and Safari?
Is there a preferred way to clear out two columns on the client side? I'm trying to duplicate this server-side code on the client:
foreach (TreeListNode tln in TreeList1.Nodes)
{
if (tln.Level == 1)
{
tln.SetValue("Weight1", DBNull.Value);
tln.SetValue("Weight2", DBNull.Value);
//I also need to set the background color of the node, but that doesn't seem to be possible either
//server-side, or client-side. How would I do that?
}
}
Hi Ken:
I suggest you to check the example attached. This example is created for the ASPxGridView, but I believe that you can implement the similar approach for the ASPxTreeList.
Thanks
Kate.
Thanks Kate. Unfortunately, I did not purchase the ASPxGridView, so I cannot run the sample. My current question has sort of evolved from its original form, so I will post it separately as "How to clear columns client-side."
Thanks.