public partial class Flights : System.Web.UI.Page { private string strcon = ConfigurationManager.ConnectionStrings["con"].ConnectionString; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { FillGrid(); GridView1.SelectedIndex = 0; } } protected void submit_Click(object sender, EventArgs e) { FlightDatabase.FlightProperties _flight = new FlightDatabase.FlightProperties(); if (txtID.Text.Length > 0) { _flight.ID = Convert.ToInt32(txtID.Text); } _flight.AirName = txtAirname.Text; _flight.Departure = Convert.ToDateTime(txtDeparture.Text); _flight.Arrival = Convert.ToDateTime(txtArrival.Text); _flight.Duration = txtDuration.Text; _flight.Stops = Convert.ToInt32(txtStops.Text); _flight.Price = txtPrice.Text; Session["obj_Airlines"] = _flight; FlightDatabase.Flight _fl = new FlightDatabase.Flight(); int rowsAffected=0; if (txtID.Text.Length > 0) { _fl.updateRecords(); } else { rowsAffected = _fl.insertRecords(); } if (rowsAffected >= 1) { lblMsg.Text = "User Registration successful"; } else { lblMsg.Text = "User Updated successfully"; } GridView1.EditIndex = -1; FillGrid(); } private void FillGrid() { FlightDatabase.Flight _fl = new FlightDatabase.Flight(); GridView1.DataSource = _fl.FillGrid(); DataBind(); _fl = null; } protected void gvw_SelectedIndexChanged(object sender, EventArgs e) { } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridViewRow _row=GridView1.Rows[e.NewEditIndex]; txtID.Text = GridView1.DataKeys[_row.RowIndex].Value.ToString(); txtAirname.Text = _row.Cells[0].Text; TextBox textDeparts = (TextBox)_row.Cells[1].FindControl("Label3"); txtDeparture.Text = textDeparts.Text; txtArrival.Text = _row.Cells[2].Text; txtDuration.Text = _row.Cells[3].Text; //TextBox txt = (TextBox)this.GridView1.Rows[e.NewEditIndex].FindControl("TextBox1"); DropDownList labelStops = (DropDownList)_row.Cells[4].FindControl("Label2"); txtStops.Text = labelStops.Text; Label labelPrice = (Label)_row.Cells[5].FindControl("Label1"); txtPrice.Text = labelPrice.Text; } protected void GridView1_RowUpdating1(object sender, GridViewUpdateEventArgs e) { } protected void txtPrice_TextChanged(object sender, EventArgs e) { } protected void GridView1_DataBound(object sender, EventArgs e) { foreach (GridViewRow txtStops in GridView1.Rows) { DropDownList labelStops = (DropDownList)txtStops.Cells[4].FindControl("Label2"); if (int.Parse(labelStops.Text) > 0) { txtStops.BackColor = System.Drawing.Color.CornflowerBlue; } } foreach (GridViewRow txtPrice in GridView1.Rows) { Label labelPrice = (Label)txtPrice.Cells[5].FindControl("Label1"); if (decimal.Parse(labelPrice.Text) > 1000) { txtPrice.BackColor = System.Drawing.Color.Gray; } } } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; FillGrid(); } protected void lbkSelect_Click(object sender, EventArgs e) { LinkButton btndetails = sender as LinkButton; GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer; txtID.Text = GridView1.DataKeys[gvrow.RowIndex].Value.ToString(); lblAirlineName.Text = gvrow.Cells[0].Text; TextBox textDeparts = (TextBox)gvrow.Cells[1].FindControl("Label3"); lblDeparture.Text = textDeparts.Text; lblArrival.Text = gvrow.Cells[2].Text; lblDuration.Text = gvrow.Cells[3].Text; DropDownList labelStops = (DropDownList)gvrow.Cells[4].FindControl("Label2"); lblStops.Text = labelStops.Text; Label labelPrice = (Label)gvrow.Cells[5].FindControl("Label1"); lblPrice.Text = labelPrice.Text; ctlModalPopupExtender.Show(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)