protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (ViewState["Stop"] == null) { DataTable dt = new DataTable(); dt.Columns.Add("name"); dt.Columns.Add("location"); dt.Columns.Add("routeId"); ViewState["Stop"] = dt; using (SqlConnection conn = new SqlConnection(DbString)) { try { DataTable DTs = new DataTable(); String query = "SELECT * from Route"; SqlDataAdapter SDA = new SqlDataAdapter(query, conn); SDA.Fill(DTs); RouteDropDown.DataSource = DTs; RouteDropDown.DataTextField = "Name"; RouteDropDown.DataValueField = "RouteID"; RouteDropDown.DataBind(); } catch (SqlException exe) { throw exe; } } } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { using (SqlConnection conn = new SqlConnection(DBstring)) { String q1 = "SELECT VehicleID,Number from Vehicle where Status = 'Active'"; SqlDataAdapter sda = new SqlDataAdapter(q1, conn); DataTable dt1 = new DataTable(); sda.Fill(dt1); if (dt1.Columns.Count != 0) { VehicleDropDown.DataSource = dt1; VehicleDropDown.DataTextField = "Number"; VehicleDropDown.DataValueField = "VehicleID"; VehicleDropDown.DataBind(); ListItem liVehicle = new ListItem("Select Vehicle", "-1"); VehicleDropDown.Items.Insert(0, liVehicle); } } using (SqlConnection con = new SqlConnection(DBstring)) { String q2 = "SELECT RouteID,Name from Route"; SqlDataAdapter sda = new SqlDataAdapter(q2, con); DataTable dt2 = new DataTable(); sda.Fill(dt2); if (dt2.Columns.Count != 0) { RouteDropDown.DataSource = dt2; RouteDropDown.DataTextField = "Name"; RouteDropDown.DataValueField = "RouteID"; RouteDropDown.DataBind(); ListItem liRoute = new ListItem("Select Route", "-1"); RouteDropDown.Items.Insert(0, liRoute); } } } }