How to add extra text to DropDownList item using C# in ASP.Net

Last Reply on Jan 05, 2017 02:25 AM By dharmendr

Posted on Jan 04, 2017 11:44 PM

Below is my code which binds 1 to 90 days as Day 1,Day 2,Day 3 so on till Day 90 in my drop down.Now for 1 t0 35 days i need to display Day 1 AMT,Day 2 AMT so on till Day 35 AMT and again from Day 36 i need to display Day 36,Day 37,Day 38 so on till Day 90.How can i do this

 protected void BindDays()
    {
        ddlDayWise.Items.Insert(0, new ListItem("--Select--", "--Select--"));
        for (int i = 1; i <= 90; i++)
        {
            ddlDayWise.Items.Insert(i,new ListItem("Day"+i,i.ToString()));
        }
    }
Posted on Jan 05, 2017 02:25 AM
kavithav says:
protected void BindDays()
    {
        ddlDayWise.Items.Insert(0, new ListItem("--Select--", "--Select--"));
        for (int i = 1; i <= 90; i++)
        {
            ddlDayWise.Items.Insert(i,new ListItem("Day"+i,i.ToString()));
        }
    }

 Replace with below

protected void BindDays()
{
    ddlDayWise.Items.Insert(0, new ListItem("--Select--", "--Select--"));
    for (int i = 1; i <= 35; i++)
    {
        ddlDayWise.Items.Insert(i, new ListItem("Day " + i + " AMT", i.ToString()));
    }
    for (int i = 36; i <= 90; i++)
    {
        ddlDayWise.Items.Insert(i, new ListItem("Day " + i, i.ToString()));
    }
}