You have to tell us which line causes the error.
Anyway, try this instead:
protected void Page_Load(object sender, EventArgs e){
if(!IsPostback){
BindAll();
}
}
private void BindAll(){
BindExpenseList();
BindPersonList();
}
private string GetConnectionString(){
return ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
}
private void BindExpenseList(){
using(SqlConnection con = new SqlConnection(GetConnectionString())){
using(SqlCommand cmd = new SqlCommand("select * from Expense_Type", con)){
con.Open();
DropDownListexpensetype.DataSource = cmd.ExecuteReader();
DropDownListexpensetype.DataTextField = "Expense_Type";
DropDownListexpensetype.DataValueField = "Expense_Type";
DropDownListexpensetype.DataBind();
}
}
}
private void BindPersonList(){
using(SqlConnection con = new SqlConnection(GetConnectionString())){
using(SqlCommand cmd = new SqlCommand("select * from [dbo].[User_details]", con)){
con.Open();
DropDownListperson.DataSource = cmd.ExecuteReader();
DropDownListperson.DataTextField = "Full_Name";
DropDownListperson.DataValueField = "Full_Name";
DropDownListperson.DataBind();
}
}
}
The idea is to decouple each binding in a separate method for you to easily maintain the code.