Hi kishore21,
Refer the below code.
HTML
<div>
<asp:DropDownList ID="drpimplement" runat="server">
<asp:ListItem Text="Tractor" Value="Tractor"></asp:ListItem>
<asp:ListItem Text="Power Tiller" Value="Power Tiller"></asp:ListItem>
<asp:ListItem Text="Cultivator 9 Tyne" Value="Cultivator 9 Tyne"></asp:ListItem>
<asp:ListItem Text="Cultivator 5 Tyne" Value="Cultivator 5 Tyne"></asp:ListItem>
<asp:ListItem Text="Rotavator" Value="Rotavator"></asp:ListItem>
<asp:ListItem Text="MB Plough (Reversible)" Value="MB Plough (Reversible)"></asp:ListItem>
<asp:ListItem Text="Disc Plough" Value="Disc Plough"></asp:ListItem>
</asp:DropDownList>
</div>
Code
protected void Page_Load(object sender, EventArgs e)
{
SortDDL(ref this.drpimplement);
}
private void SortDDL(ref DropDownList objDDL)
{
ArrayList textList = new ArrayList();
ArrayList valueList = new ArrayList();
foreach (ListItem li in objDDL.Items)
{
textList.Add(li.Text);
}
textList.Sort();
foreach (object item in textList)
{
string value = objDDL.Items.FindByText(item.ToString()).Value;
valueList.Add(value);
}
objDDL.Items.Clear();
for (int i = 0; i < textList.Count; i++)
{
ListItem objItem = new ListItem(textList[i].ToString(), valueList[i].ToString());
objDDL.Items.Add(objItem);
}
}
Output
Cultivator 5 Tyne
Cultivator 9 Tyne
Disc Plough
MB Plough (Reversible)
Power Tiller
Rotavator
Tractor