我需要在树视图中显示目录结构,用户应该能够在树视图的任何节点上添加文件夹。
我已经构建了树结构并将新文件夹添加到所选节点。添加新文件夹后,我重新绑定了树视图。我的问题是,在重新绑定后,我需要在树视图中将当前创建的文件夹显示为选定节点。
aspx页面:
<div>
<asp:TextBox ID="txtFolderName" runat="server" Text="Folder name" ForeColor="Gray"
onblur="WaterMark(this, event);" onfocus="WaterMark(this, event);">
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtFolderName"
ErrorMessage="*" ValidationGroup="AddFolder"></asp:RequiredFieldValidator>
<asp:Button ID="btnAddFolder" runat="server" Text="Add folder" OnClick="btnAddFolder_Click"
ValidationGroup="AddFolder" />
</div>
<asp:TreeView ID="trvwDouments" runat="server" ExpandDepth="1" OnSelectedNodeChanged="trvwDouments_SelectedNodeChanged"
SelectedNodeStyle-BackColor="Silver">
</asp:TreeView>
在“添加文件夹点击”
上添加新文件夹的代码if (hdnDirPath.Value != string.Empty)
{
string dirPath = hdnDirPath.Value + "\\" + txtFolderName.Text;
DirectoryInfo newDirectory = new DirectoryInfo(dirPath);
try
{
if (!Directory.Exists(dirPath))
{
newDirectory.Create();
BindTreeview();
}
else
lblErrorMessage.Text = "Directory already exists!!";
}
catch (Exception ex)
{
throw ex;
}
}
我需要帮助将新创建的节点设置为所选节点。