This is My Model
public class InsertOrder
{
public int CustomerId { get; set; }
public string CustomerName { get; set; }
}
public List<InsertOrder> getcustomerid()
{
List<InsertOrder> customerlist = new List<InsertOrder>();
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString);
SqlDataReader Datareader;
{
using (SqlCommand command = new SqlCommand("SELECT CustomerID,FirstName FROM customers", connection))
{
connection.Open();
Datareader = command.ExecuteReader();
while (Datareader.Read())
{
InsertOrder ID = new InsertOrder();
ID.CustomerId = Convert.ToInt32(Datareader["CustomerID"]);
ID.CustomerName = Datareader["FirstName"].ToString();
customerlist.Add(ID);
}
Datareader.Close();
return customerlist;
}
}
}
How to give in the view page
InsertOrderto?InsertOrderto. In Moksh's answer below, it assumes you have a model with a propertyint SampleDropDownValueso theCustomerIDvalue of the selectedInsertOrderis bound to the value ofSampleDropDownValue