Dear Sir,
I unable to insert value Year, Month, INDICATER_TYPE.
<form id="form1" runat="server">
<table border="1" cellpadding="0" cellspacing="0" align="left" weight="400" class="auto-style6">
<tr>
<td height="30" valign="top" colspan="2" bgcolor="navy" class="auto-style3">
<br>
<font color="#FF9900" size="+2" face="Tahoma"><b>Safety Lead /Lag</b></font></td>
<br />
</tr>
<table border="1" cellpadding="0" cellspacing="0" align="left" weight="400" class="auto-style6">
<tr>
<br />
<td class="auto-style18">
<b>Emp ID </span>:</b><br />
<asp:TextBox ID="txtEMPNO" runat="server" Width="140" Height="25px" />
</td>
<td class="auto-style18">
<b>Name</span>:</b><br />
<asp:TextBox ID="txtNAME" runat="server" Width="140" Height="25px" />
</td>
<td class="auto-style18">
<b>Department</span> :</b><br />
<asp:TextBox ID="txtDEPARTMENT" runat="server" Width="140" Height="25px" />
</td>
<td><strong>Select Year:</b></strong><br />
<asp:DropDownList ID="ddl_Year" runat="server" Width="140" Height="25px">
</asp:DropDownList></strong>
</td>
<td><b>Select Month:</b><strong><br />
<asp:DropDownList ID="ddl_Month" runat="server" Width="140" Height="25px">
</asp:DropDownList></strong></a></td>
<td class="auto-style4"><a align="left" href="login.aspx"><strong><font colore="red">Logout</font></strong></a></td>
</tr>
<tr>
<td class="auto-style18">
<strong>Description</strong><b>:</b><br />
<asp:DropDownList ID="DropDownList2" runat="server" CssClass="auto-style2" Height="27px" Width="169px" onChange="changecat(this.value);">
<asp:ListItem>--Select--</asp:ListItem>
<asp:ListItem>Visits</asp:ListItem>
<asp:ListItem>Training</asp:ListItem>
<asp:ListItem>PepTalk</asp:ListItem>
<asp:ListItem>Analaysis</asp:ListItem>
</asp:DropDownList>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="DropDownList1"
ErrorMessage="Required!" ForeColor="Red" InitialValue="--Select--"></asp:RequiredFieldValidator>
</td>
<td class="auto-style11">
<strong>Type</strong><b>:</span><br />
</b>
<asp:DropDownList ID="DropDownList3" runat="server" CssClass="auto-style2" Height="27px" Width="169px">
<asp:ListItem>--Select--</asp:ListItem>
</asp:DropDownList>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DropDownList1"
ErrorMessage="Required!" ForeColor="Red" InitialValue="--Select--"></asp:RequiredFieldValidator>
</td>
<td class="auto-style12">
<b>Complied:</span><br />
</b>
<asp:DropDownList ID="DropDownList1" runat="server" CssClass="auto-style2" Height="27px" Width="169px">
<asp:ListItem>--Select--</asp:ListItem>
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:DropDownList>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="DropDownList1"
ErrorMessage="Required!" ForeColor="Red" InitialValue="--Select--"></asp:RequiredFieldValidator>
</td>
<td class="auto-style5">
<b>Date:<br />
<asp:TextBox ID="txtDATE" runat="server" placeholder="mm/dd/yyyy" Height="25px" Width="160px"></asp:TextBox>
<br />
<td class="auto-style5">
<strong>Remark:</strong>
<asp:TextBox ID="txtREMARK" runat="server" Height="25px" Width="180px" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Remark can't be blank." ControlToValidate="txtREMARK" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
<td class="auto-style4">
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="Insert" CssClass="auto-style1" Height="25px" Width="100px" />
</td>
</tr>
<table border="1" cellpadding="0" cellspacing="0" align="left" weight="400" class="auto-style6">
<tr>
<td class="auto-style6">
<script type="text/javascript">
var TargetBaseControl = null;
window.onload = function () {
try {
//get target base control.
TargetBaseControl =
document.getElementById('<%= this.GridView1.ClientID %>');
}
catch (err) {
TargetBaseControl = null;
}
}
function TestCheckBox() {
if (TargetBaseControl == null) return false;
//get target child control.
var TargetChildControl = "chkSelect";
//get all the control of the type INPUT in the base control.
var Inputs = TargetBaseControl.getElementsByTagName("input");
for (var n = 0; n < Inputs.length; ++n)
if (Inputs[n].type == 'checkbox' &&
Inputs[n].id.indexOf(TargetChildControl, 0) >= 0 &&
Inputs[n].checked)
return true;
alert('Select at least one checkbox!');
return false;
}
</script>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<script type='text/javascript'>
$(function () {
// When a Button is clicked on your page, disable everything and display your loading element
$(':button,:btnSendMail_Click').click(function () {
// Disable everything
$('*').prop('disabled', true);
// Display your loading image (centered on your screen)
$('').append("<img style='top: 45%; position: absolute; height: 100px; width: 100px;background: black;left: 45%;' src='<img src="30.gif" />' />");
});
});
</script>
<td class="auto-style6"> <td class="auto-style6"> <td class="auto-style6">
<asp:Button ID="btnSendMail0" runat="server" CausesValidation="true" CssClass="auto-style8" Height="31px" OnClick="btnSendMail_Click" OnClientClick="javascript:return TestCheckBox();" Text="Submit " Width="75px" />
<td class="auto-style6"> <td class="auto-style6"> <td class="auto-style6">
</table>
</form>
<script src="js/jquery-3.4.1.min.js"></script>
<script src="jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>
<script>
$(document).ready(function () {
$("#txtDATE").datepicker({ minDate: "-1M -28D", maxDate: "+0M +0D", changeMonth: true, changeYear: true });
});
</script>
<script>
var mealsByCategory = {
Training: ["Lead"],
Visits: ["Lead"],
Analaysis: ["Lag"],
PepTalk: ["Lead"]
}
function changecat(value) {
if (value.length == 0) document.getElementById("DropDownList3").innerHTML = "<option></option>";
else {
var catOptions = "";
for (categoryId in mealsByCategory[value]) {
catOptions += "<option>" + mealsByCategory[value][categoryId] + "</option>";
}
document.getElementById("DropDownList3").innerHTML = catOptions;
}
}
</script>
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.BindGrid();
}
int currentYear = DateTime.Today.Year;
ddl_Year.Items.Clear();
ddl_Year.Items.Add("Select");
for (int i = 2; i >= 0; i--)
{
int fy = currentYear - i;
int fy1 = fy + 1;
if (DateTime.Now.Date > Convert.ToDateTime(fy + "-03-31").Date)
{
ddl_Year.Items.Add(fy.ToString() + "-" + fy1.ToString());
}
}
txtDATE.Text = DateTime.Now.ToString();
if (Session["EmpName"] == null)
Response.Redirect("login.aspx");
else
{
String EmplooyeId = Convert.ToString((int)Session["empid"]);
String empid = Session["empid"].ToString();
String EmpName = Session["EmpName"].ToString();
String Department = Session["Department"].ToString();
txtEMPNO.Text = "" + empid + "";
txtNAME.Text = "" + EmpName + "";
txtDEPARTMENT.Text = "" + Department + "";
}
{
DateTime currentDate = DateTime.Now;
List<ListItem> items = new List<ListItem>();
items.Add(new ListItem
{
Text = currentDate.AddMonths(-1).Month.ToString(),
Value = currentDate.AddMonths(-1).Month.ToString()
});
items.Add(new ListItem
{
Text = currentDate.Month.ToString(),
Value = currentDate.Month.ToString()
});
ddl_Month.DataSource = items;
ddl_Month.DataTextField = "Text";
ddl_Month.DataValueField = "Text";
ddl_Month.DataBind();
}
}
protected void Insert(object sender, EventArgs e)
{
string EMPNO = txtEMPNO.Text;
string NAME = txtNAME.Text;
string DEPARTMENT = txtDEPARTMENT.Text;
string Year = ddl_Year.Text;
string Month = ddl_Month.Text;
string DATE = txtDATE.Text;
string INDICATER_TYPE = DropDownList2.Text;
string INDICATER_Desc = DropDownList3.Text;
string COMPLIED = DropDownList1.Text;
string REMARK = txtREMARK.Text;
DropDownList2.Text = "";
DropDownList3.Text = "";
DropDownList1.Text = "";
txtREMARK.Text = "";
string query = "INSERT INTO lead_lag VALUES(@EMPNO,@NAME, @DEPARTMENT,@Year,@Month,@DATE,@INDICATER_TYPE,@INDICATER_Desc,@COMPLIED,@REMARK,@flag )";
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Parameters.AddWithValue("@EMPNO", EMPNO);
cmd.Parameters.AddWithValue("@NAME", NAME);
cmd.Parameters.AddWithValue("@DEPARTMENT", DEPARTMENT);
cmd.Parameters.AddWithValue("@Year", Year);
cmd.Parameters.AddWithValue("@Month", Month);
cmd.Parameters.AddWithValue("@DATE", DATE);
cmd.Parameters.AddWithValue("@INDICATER_TYPE", INDICATER_TYPE);
cmd.Parameters.AddWithValue("@INDICATER_Desc", INDICATER_Desc);
cmd.Parameters.AddWithValue("@COMPLIED", COMPLIED);
cmd.Parameters.AddWithValue("@REMARK", REMARK);
cmd.Parameters.AddWithValue("@flag", "");
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
this.BindGrid();
}
protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkAll = (CheckBox)GridView1.HeaderRow.FindControl("chkSelectAll");
foreach (GridViewRow gvRow in GridView1.Rows)
{
CheckBox chkSel = (CheckBox)gvRow.FindControl("chkSelect");
if (
chkAll.Checked)
{
chkSel.Checked = true;
}
else
{
chkSel.Checked = false;
}
}
}
}