My existing WebDataTree uses server-side code to perform its Search function:
User enters search string in textbox; clicks "Search" button; code searches nodes for next occurrence of search string; click again, find next occurrence; until there are no more occurrences.
Due to the length of the tree, we're using Load On Demand, so there's really just the first layer of data being shown.
ASP.NET code:
<
ig:WebDataTree ID="tvwUserGroup" runat="server" CheckBoxMode="BiState" DataLoadingMessage="Loading ... Please be patient" EnableConnectorLines="True" EnableExpandOnClick="True" EnableSingleBranchExpand="True" Height="600px" InitialDataBindDepth="2" InitialExpandDepth="2" Width="300px">
<DataBindings>
<ig:DataTreeNodeBinding DataMember="drGroups" TextField="Name" ValueField="Guid" />
</DataBindings>
</ig:WebDataTree>
cs Code for Search:
protected void btnSearchUserGroup_Click(object sender, EventArgs e)
{
if (btnSearchUserGroup.Text == "Search")
mFoundCurrentIndex = 0;
ViewState[
"mFoundCurrentIndex"] = mFoundCurrentIndex;
FindNodesUserGroups();
}
// end if
else if (btnSearchUserGroup.Text == "Find Next")
if (ViewState["mFoundCurrentIndex"] != null)
mFoundCurrentIndex = (
int)ViewState["mFoundCurrentIndex"];
mFoundCurrentIndex += 1;
FindNext(tvwUserGroups.Nodes);
// end else if
// end method btnSearchUserGroup_Click
private void FindNodesUserGroups()
string searchFor = "";
searchFor = txtSearchUserGroup.Text;
DataTreeNodeCollection pNodes = new DataTreeNodeCollection();
pNodes = tvwUserGroups.Nodes;
if (searchFor.Length > 0)
mFoundNodes = WalkTree(searchFor, pNodes);
if (mFoundNodes.Count > 1)
btnSearchUserGroup.Text =
"Find Next";
lblUserSearchResults.Text = mFoundNodes.Count +
" results found";
else
"Search";
// end else
FindNext(pNodes);
return;
// end method FindNodes
private void FindNext(DataTreeNodeCollection pNodes)
DataTreeNode foundNode = new DataTreeNode();
string foundNodeText = "";
if (mFoundNodes == null)
if (mFoundCurrentIndex >= -1)
if (mFoundNodes != null && mFoundNodes.Count - 1 >= mFoundCurrentIndex)
foundNode = (
DataTreeNode)mFoundNodes[mFoundCurrentIndex];
foundNodeText = foundNode.Text;
for (int i = 0; i < pNodes.Count; i++)
if (pNodes[i].Text == foundNodeText)
pNodes[i].Selected =
true;
pNodes[i].Expanded =
pNodes[i].CheckState =
CheckBoxState.Checked;
false;
CheckBoxState.Unchecked;
FindNext(pNodes[i].Nodes);
// end for
lblUserSearchResults.Text =
"No further results found.";
"mFoundCurrentIndex"] = null;
// end method FindNext
private ArrayList WalkTree(string searchFor, DataTreeNodeCollection pNodes)
ArrayList oRet;
ArrayList iTemp;
oRet =
new ArrayList();
foreach (DataTreeNode node in pNodes)
if (node.Text.ToLower().Contains(searchFor.ToLower()))
oRet.Add(node);
iTemp = WalkTree(searchFor, node.Nodes);
oRet.AddRange(iTemp.ToArray());
// end foreach
return oRet;
// end method WalkTree
I've been able to work this on client-side using a regular asp:TreeView, but I see that the HTML Source for the asp:TreeView translates to a table, while the WebDataTree is an unordered list. I also see that the asp:TreeView uses actual "<input type='checkbox'>" tags for its checkboxes, while the WebDataTree uses <img> tags.
Any ideas on how to make this work on client-side?
Thanks,
Michell
Believe it or not, I actually figured this one out on my own.
By the way, I apologize for all the white spa
I used the followig JavaScript to walk the tree and find each entry that matched my searchString. Note that I've added a couple of <asp:Hidden> controls to keep track of how far down the tree the search had gotten and when the search of the tree was complete:
function
var searchString = document.getElementById('<%= txtSearchUserGroup.ClientID %>').value.toLowerCase();
if (itemCount == "") {
itemCount = -1;
document.getElementById(
'<%= hdnCounter.ClientID %>').value = itemCount;
for (var i = 1; i <= liArray.length; i++) {
if (parseInt(itemCount) < i && i < liArray.length) {
var liItem = liArray[i].outerText.toLowerCase();
if (liItem.indexOf(searchString) > -1) {
itemCount = i;
"SearchUserGroup").value = "Find Next";
'<%= hdnComplete.ClientID %>').value = "";
liArray[i].style.backgroundColor =
"lightBlue";
break;
if (i == liArray.length) {
'<%= hdnComplete.ClientID %>').value = "Complete";
"transparent";
} // end else
"SearchUserGroup").value = "Search";
'<%= hdnCounter.ClientID %>').value = "";
'<%= txtSearchIndex.ClientID %>').value = itemCount.toString();