Hi sir,
I have database table name events.
Id name property
1 |
Cleaning |
Button |
2 |
Loading |
Button |
3 |
travelling |
Button |
4 |
Security start |
Button |
5 |
Security end |
Button |
6 |
Captain Name |
TextBox |
7 |
Event number |
TextBox |
8 |
department |
TextBox |
9 |
name |
TextBox |
. . . and so on |
|
|
From this table I fetch data and made form dynamic.
Then I have to input information in this form and want to save this form data into database table.
my code is here
<%@ 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="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div class="form-group" style="margin: 30px">
<div class='input-group date' style="width: 200px">
<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>
<script type="text/javascript">
$(function () {
$('.datepicker').datetimepicker({
format: 'LT'
});
});
$('.datepicker').click(function () {
return false;
});
</script>
</div>
</div>
</form>
</body>
</html>
using System.Data;
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 = DateTime.Now.ToShortTimeString();
btn.ID = "btn" + buttons[i]["name"].ToString();
// btn.BackColor = Color.Green;
btn.CssClass = "datepicker";
//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);
}
}
}
My database table Is EventRecord which column is like this.
ID Cleaning Loading travelling SecutityStart securityEnd captainName Eventnumber Department name ………And so on