Hi sir,
I have dropdown list through which user select station. And on the basis of that the appeared on two GridView as arrival and departure.
Then I select the GridView row and move to the next page.
On next page I have a dynamic form that fetch data from database and make a form.
I have database table from where data fetch into next is like below.
Id eventtype eventname property.
1 arrival name Textbox
1 arrival class Textbox
1 departure name Textbox
1 departure class Button
1 arrival boarding Button
and so on.
I want that when user select GridView from arrival grid. Then on next page event type arrival data should show. When user select row from departure GridView then on next page event type departure data should appear.
<form id="form1" runat="server">
<div>
Station
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>DXB</asp:ListItem>
<asp:ListItem>AUH</asp:ListItem>
<asp:ListItem>SHJ</asp:ListItem>
<asp:ListItem>RUH</asp:ListItem>
<asp:ListItem>JED</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Go" Width="36px" />
<br />
<br />
<asp:GridView ID="GridView3" runat="server">
</asp:GridView>
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>
<br />
<br />
<asp:Label ID="Label2" runat="server"></asp:Label>
<br />
<asp:GridView ID="GridView2" runat="server" OnSelectedIndexChanged="GridView2_SelectedIndexChanged" OnRowDataBound="GridView2_RowDataBound">
<Columns>
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>
</div>
</form>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
showdata();
}
}
protected void showdata()
{
String cs = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT flightdate,flightno,origin,destination,scheduleddeparture,estimateddeparture,departurestatus,scheduledarrival,estimatedarrival,arrivalstatus,aircraftreg FROM flights", con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows == true)
{
GridView3.DataSource = dr;
GridView3.DataBind();
}
}
}
protected void showdatadeparture()
{
String cs = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT flightdate,flightno,origin,destination,scheduleddeparture,estimateddeparture,departurestatus,scheduledarrival,estimatedarrival,arrivalstatus,aircraftreg FROM flights where origin= '" + DropDownList1.Text + "' ", con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows == true)
{
GridView1.DataSource = dr;
GridView1.DataBind();
}
}
}
protected void showdataarrival()
{
String cs = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT flightdate,flightno,origin,destination,scheduleddeparture,estimateddeparture,departurestatus,scheduledarrival,estimatedarrival,arrivalstatus,aircraftreg FROM flights where destination= '" + DropDownList1.Text + "' ", con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows == true)
{
GridView2.DataSource = dr;
GridView2.DataBind();
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TimeTrackerpage.aspx.cs" Inherits="AirportOppsTimeTracker.TimeTrackerpage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<style>
.datepicker { }
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblUserId" runat="server" />
<asp:Label ID="lblSession" runat="server" />
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading">Airport Operations Tracking System</div>
<div class="panel-body">
<asp:Panel runat="server" ID="pnlDynamic"></asp:Panel>
</div>
</div>
</div>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.css" type="text/css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js" type="text/javascript"></script>
<!-- Bootstrap DatePicker -->
<script type="text/javascript">
$(function () {
$('.datepicker').datepicker({
changeMonth: true,
changeYear: true,
format: "dd/mm/yyyy",
language: "tr"
});
});
</script>
</div>
</form>
</body>
</html>
namespace AirportOppsTimeTracker
{
public partial class TimeTrackerpage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string query = @"SELECT * FROM [Events]";
query += "ORDER BY ";
query += "CASE WHEN property = 'TextBox' THEN 0 ";
query += "WHEN property = 'Button' THEN 1 ";
query += "END";
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand(query, con))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dt);
}
}
}
DataRow[] textBoxes = dt.Select("property='TextBox'");
DataRow[] buttons = dt.Select("property='Button'");
Table table = new Table();
TableRow tr = new TableRow();
for (int i = 0; i < textBoxes.Length; i++)
{
TableCell cell = new TableCell();
Label lbl = new Label();
lbl.Text = textBoxes[i]["name"].ToString();
cell.Controls.Add(lbl);
Literal lt = new Literal();
lt.Text = "<br /><br />";
cell.Controls.Add(lt);
TextBox txt = new TextBox();
txt.ID = "txt" + textBoxes[i]["name"].ToString();
cell.Controls.Add(txt);
if (i % 3 == 0 && i != 0)
{
tr = new TableRow();
}
else
{
tr.Cells.Add(cell);
}
if (i % 2 == 0 && i != 0)
{
table.Rows.Add(tr);
}
else
{
tr.Cells.Add(cell);
if (textBoxes.Length == i + 1)
{
table.Rows.Add(tr);
}
}
}
tr = new TableRow();
for (int i = 0; i < buttons.Length; i++)
{
TableCell cell = new TableCell();
Label lbl = new Label();
lbl.Text = buttons[i]["name"].ToString();
cell.Controls.Add(lbl);
Literal lt = new Literal();
lt.Text = "<br /><br />";
cell.Controls.Add(lt);
Button btn = new Button();
btn.Text = "Time";
btn.ID = "btn" + buttons[i]["name"].ToString();
btn.BackColor = Color.Green;
btn.Click += new EventHandler(this.OnSubmit);
cell.Controls.Add(btn);
lt = new Literal();
lt.Text = "<br /><br />";
cell.Controls.Add(lt);
Label lblTime = new Label();
lblTime.ID = "lbl" + buttons[i]["name"].ToString();
cell.Controls.Add(lblTime);
//tr.Cells.Add(cell);
if (i % 3 == 0 && i != 0)
{
tr = new TableRow();
}
else
{
tr.Cells.Add(cell);
}
if (i % 2 == 0 && i != 0)
{
table.Rows.Add(tr);
}
else
{
tr.Cells.Add(cell);
if (buttons.Length == i + 1)
{
table.Rows.Add(tr);
}
}
}
//table.Rows.Add(tr);
pnlDynamic.Controls.Add(table);
}
protected void OnSubmit(object sender, EventArgs e)
{
string btnId = (sender as Button).ID;
string lblId = (sender as Button).ID.Replace("btn", "lbl");
(sender as Button).Enabled = false;
(pnlDynamic.FindControl(btnId) as Button).BackColor = Color.Gray;
(pnlDynamic.FindControl(lblId) as Label).Text = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
}
}
}