Hi dnnyobi,
Check this example. Now please take its reference and correct your code.
HTML
<asp:TreeView ID="TreeView1" runat="server">
</asp:TreeView>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[] characters = new string[] { "A", "B", "CH", "D", "E", "Ẹ", "F", "G", "GB", "GH", "GW", "H",
"I", "Ị", "J", "K", "KP", "KW", "L", "M", "N", "NW", "NY", "Ṇ",
"O", "Ọ", "P", "S", "Ṣ", "T", "U", "Ụ", "V", "W", "Y", "Z", "Ẓ"
};
// Get the DataTable from Database.
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[] { new System.Data.DataColumn("Word", typeof(string)) });
dt.Rows.Add("Abu");
dt.Rows.Add("Ịjeoma");
dt.Rows.Add("Baba");
dt.Rows.Add("Chekube");
dt.Rows.Add("Ṣeka");
dt.Rows.Add("Daniel");
dt.Rows.Add("Ụdu");
dt.Rows.Add("Ego");
dt.Rows.Add("Humpty");
dt.Rows.Add("Ify");
dt.Rows.Add("Ẹnuwa");
dt.Rows.Add("Samuel");
dt.Rows.Add("Ulo");
List<string> newLists = new List<string>();
foreach (string character in characters)
{
foreach (System.Data.DataRow dr in dt.Rows)
{
if (dr["Word"].ToString().StartsWith(character))
{
if (!newLists.Contains(dr["Word"].ToString()))
{
newLists.Add(dr["Word"].ToString());
TreeView1.Nodes.Add(new TreeNode { Text = dr["Word"].ToString() });
}
}
}
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim characters As String() = New String() {"A", "B", "CH", "D", "E", "Ẹ", "F", "G", "GB", "GH", "GW", "H", "I", "Ị", _
"J", "K", "KP", "KW", "L", "M", "N", "NW", "NY", "Ṇ", "O", "Ọ", "P", "S", _
"Ṣ", "T", "U", "Ụ", "V", "W", "Y", "Z", "Ẓ"}
' Get the DataTable from Database.
Dim dt As System.Data.DataTable = New System.Data.DataTable()
dt.Columns.AddRange(New System.Data.DataColumn() {New System.Data.DataColumn("Word", GetType(String))})
dt.Rows.Add("Abu")
dt.Rows.Add("Ịjeoma")
dt.Rows.Add("Baba")
dt.Rows.Add("Chekube")
dt.Rows.Add("Ṣeka")
dt.Rows.Add("Daniel")
dt.Rows.Add("Ụdu")
dt.Rows.Add("Ego")
dt.Rows.Add("Humpty")
dt.Rows.Add("Ify")
dt.Rows.Add("Ẹnuwa")
dt.Rows.Add("Samuel")
dt.Rows.Add("Ulo")
Dim newLists As List(Of String) = New List(Of String)()
For Each character As String In characters
For Each dr As System.Data.DataRow In dt.Rows
If dr("Word").ToString().StartsWith(character) Then
If Not newLists.Contains(dr("Word").ToString()) Then
newLists.Add(dr("Word").ToString())
TreeView1.Nodes.Add(New TreeNode With {.Text = dr("Word").ToString()})
End If
End If
Next
Next
End If
End Sub
Output
Abu
Baba
Daniel
Ego
Ẹnuwa
Humpty
Ify
Ịjeoma
Samuel
Ṣeka
Ulo
Ụdu