Hi dnnyobi,
Check this sample. now take its reference.
HTML
<table>
<tr>
<td><asp:GridView ID="gvUnsortedList" runat="server" Caption="Without Sorted List">
</asp:GridView></td>
<td><asp:GridView ID="gvSortedList" runat="server" Caption="Sorted List">
</asp:GridView></td>
</tr>
</table>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
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", "Ẓ"
};
List<string> newLists = new List<string>();
List<string> lists = new List<string>();
lists.Add("Andrea");
lists.Add("Ọare");
lists.Add("Elgar");
lists.Add("Ṇick");
lists.Add("Ẓack");
lists.Add("Humpty");
lists.Add("Daniel");
lists.Add("Ẹryant");
lists.Add("Grooks");
lists.Add("Jack");
lists.Add("KWality");
lists.Add("GHooo");
foreach (string character in characters)
{
foreach (string list in lists)
{
if (list.StartsWith(character))
{
if (!newLists.Contains(list))
{
newLists.Add(list);
}
}
}
}
this.gvUnsortedList.DataSource = lists;
this.gvUnsortedList.DataBind();
this.gvSortedList.DataSource = newLists;
this.gvSortedList.DataBind();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
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", "Ẓ"
}
Dim newLists As List(Of String) = New List(Of String)()
Dim lists As List(Of String) = New List(Of String)()
lists.Add("Andrea")
lists.Add("Ọare")
lists.Add("Elgar")
lists.Add("Ṇick")
lists.Add("Ẓack")
lists.Add("Humpty")
lists.Add("Daniel")
lists.Add("Ẹryant")
lists.Add("Grooks")
lists.Add("Jack")
lists.Add("KWality")
lists.Add("GHooo")
For Each character As String In characters
For Each list As String In lists
If list.StartsWith(character) Then
If Not newLists.Contains(list) Then
newLists.Add(list)
End If
End If
Next
Next
Me.gvUnsortedList.DataSource = lists
Me.gvUnsortedList.DataBind()
Me.gvSortedList.DataSource = newLists
Me.gvSortedList.DataBind()
End Sub
Screenshot