SRTING DROPDOWN LIST

Please review code below.   I need to sort the data in dropdown lists for "CondBY" and "InspBy" in "ASCENDING ORDER" or alphabetical order.   I need assistance with this code.

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            FillDropdown(CondBY);
            FillDropdown(InspBy1);

        }

    }

        con.Open();
        SqlCommand cmd = new SqlCommand("select * from EmpData", con);
        SqlDataAdapter dap = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        dap.Fill(ds);
        ddl.DataSource = ds;
        ddl.DataTextField = "Name1";//Database table filed name for display in dropdown
        ddl.DataValueField = "EmpNo";//display in textbox when select dropdown field
        ddl.DataBind();

    }

    protected void CondBY_SelectedIndexChanged(object sender, EventArgs e)
    {
        EmpAP.Text = CondBY.SelectedValue.ToString();// get value form dropdown

    }
    protected void InspBy1_SelectedIndexChanged(object sender, EventArgs e)
    {
        EmpAP1.Text = InspBy1.SelectedValue.ToString();// get value form dropdown
    
 
    }

}

Open in new window

BOEING39Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
BOEING39Connect With a Mentor Author Commented:
Thx I sorted it via the select statement per below:  


("select * from EmpData order by Name1", con);
0
 
Bob LearnedCommented:
If you are getting that data from the database, then you could sort it there.
0
 
BOEING39Author Commented:
Researched solution on the web.  Statement solution was the best explanation and associated code to resolve problem.
0
All Courses

From novice to tech pro — start learning today.