protected void GridView_SelectedIndexChanged(object sender, EventArgs e) { RouteId.Visible = true; RouteName.Visible = true; VehicleDropDown.Visible = true; UpdateVehicle.Visible = true; RouteId.Text = GridView.SelectedRow.Cells[1].Text; RouteName.Text = GridView.SelectedRow.Cells[3].Text; 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); } } }
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 DriverID,Name from Driver where Status = 'Active'"; SqlDataAdapter sda = new SqlDataAdapter(q2, con); DataTable dt2 = new DataTable(); sda.Fill(dt2); if (dt2.Columns.Count != 0) { DriverDropDown.DataSource = dt2; DriverDropDown.DataTextField = "Name"; DriverDropDown.DataValueField = "DriverID"; DriverDropDown.DataBind(); ListItem LiDriver = new ListItem("Select driver", "-1"); DriverDropDown.Items.Insert(0, LiDriver); } } } }