How to get the values into text boxes from asp:treeview link?

Raki 481 Reputation points
2023-03-02T21:59:16.84+00:00

Hello,

i am working on a web application where using ASP:treeview control to display files link so that user can click and get the values into respective textboxes. my link file name format is "001193 - La Cabana - Ins Boiler and Machinery - 03-29-2023.pdf". so i have four text boxes to contain values from the link as soon as user click the link. so far i was able to manage populate three values into text boxes except Date value. For me only first two digit(03) getting not whole date. what i need to tweak to get the whole date into text box? Below is the code.

Thanks


<asp:TreeView ID="TreeView1" runat="server" _ImageSet="XPFileExplorer" NodeIndent="15" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged">
                            <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
                            <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" HorizontalPadding="2px"
                                NodeSpacing="0px" VerticalPadding="2px"></NodeStyle>
                            <ParentNodeStyle Font-Bold="true" />
                            <SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" HorizontalPadding="0px"
                                VerticalPadding="0px" />
                        </asp:TreeView>

 protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
        {
            try
            {
                String filename = ((System.Web.UI.WebControls.TreeView)sender).SelectedValue;

                TreeNode selectedNode = TreeView1.SelectedNode;
                string[] fileNameParts = selectedNode.Text.Split('-');
               

                string projectNumber = fileNameParts[0].Trim();
                string projectName = fileNameParts[1].Trim();
                string insuranceType = fileNameParts[2].Trim();
                string fileDate = fileNameParts[3].Trim().Replace(".pdf", "");


                //string projectNumber = selectedNode.Text.Split('-')[0].Trim();
                //string projectName = selectedNode.Text.Split('-')[1].Trim();
                //string insuranceType = selectedNode.Text.Split('-')[2].Trim();
                //string[] nodeTextparts2 = nodeTextParts[3].Split('.');
                //string datePattern = @"\d{2}/\d{2}/\d{4}";
                //string date = "";
                //foreach (string part in nodeTextparts)
                //{
                //    Match match = Regex.Match(part.Trim(), datePattern);
                //    if (match.Success)
                //    {
                //        date = match.Value;
                //        break;
                //    }
                //}
                //string effectiveDate = filename[3].ToString();
                //string FinaleffectiveDate = nodeTextparts2[0].ToString();
                
                String rootDirectory = AppDomain.CurrentDomain.BaseDirectory;

                String relativePath = filename.Replace(rootDirectory, "");
                

                RadPdfViewer1.PdfjsProcessingSettings.File = relativePath;
                RadPdfViewer1.Visible = true;

                // Fill up text boxes values from the link 
                rad_txtProjectNumber.Text = projectNumber;
                rad_txtprojectName.Text = projectName;
                rad_txtInsuranceType.Text = insuranceType;
                rad_txtEffectivedate.Text = fileDate;
                
            }
            catch (Exception ex)
            {
                //lblerror.Text = ex.Message;
                //lblerror.Visible = true;
            }

        }
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,479 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,905 questions
0 comments No comments
{count} votes

Accepted answer
  1. XuDong Peng-MSFT 10,511 Reputation points Microsoft Vendor
    2023-03-03T06:38:44.55+00:00

    Hi @Raki,

    If you just want to get whole date string from SelectNode Text. You can try these code below:

    string NodeText = selectedNode.Text;
    string pattern = @"\b\d{2}-\d{2}-\d{4}\b";
    Match match = Regex.Match(NodeText, pattern);
    
    if (match.Success) { 
         string fileDate = match.Value;
       }
    

    Result:

    User's image

    Best regards,

    Xudong Peng


    If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.