> Add
AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True"
AutoGenerateSelectButton="True"
these properties to grid view tag.(code below)
<asp:GridView ID="GridView1" runat="server" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" AutoGenerateSelectButton="True" AllowSorting="True">
</asp:GridView>
or in properties of grid view, apply to true(screenshot below)
or
ASPX Page
<%@ Page Title="::Batch Update ::" Language="C#" MasterPageFile="~/View/Admin/Admin.master" AutoEventWireup="true" Culture="en-GB" CodeFile="BatchUpdate.aspx.cs" Inherits="View_Admin_Master_BatchUpdate" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script src="../js/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="../js/bootstrap.min.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:Label ID="Lbl_Attendance" runat="server" Text='<%#Eval("REBD_Upload_AttendenceDOC") %>'
Visible="false"></asp:Label>
<fieldset class="basic_d" style="width: 100%;">
<asp:ScriptManager ID="scriptman" runat="server">
</asp:ScriptManager>
<center>
<asp:Label ID="lbl_error" runat="server" Visible="false"></asp:Label>
</center>
<legend>Student Batch Update</legend>
<asp:UpdatePanel ID="updatnelPanel" runat="server">
<ContentTemplate>
<div class="row">
<div class="col-sm-4">
<label style="color: #333333;">
Select State</label>
<asp:DropDownList ID="drp_state" runat="server" CssClass="form-control" AutoPostBack="true"
OnSelectedIndexChanged="drp_state_SelectedIndexChanged">
</asp:DropDownList>
</div>
<div class="col-sm-4">
<label style="color: #333333;">
Select Training Partner</label>
<asp:DropDownList ID="drp_TrainingPartner" runat="server" CssClass="form-control"
AutoPostBack="true" OnSelectedIndexChanged="drp_TrainingPartner_SelectedIndexChanged">
</asp:DropDownList>
<br />
</div>
<div class="col-sm-4">
<label style="color: #333333;">
Select Training Partner Batch</label>
<asp:DropDownList ID="drp_batch" runat="server" CssClass="form-control" AutoPostBack="True"
OnSelectedIndexChanged="drp_batch_SelectedIndexChanged">
</asp:DropDownList>
<br />
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="drp_batch" />
</Triggers>
</asp:UpdatePanel>
</fieldset>
<div class="table-responsive" style="margin-top: 15px;">
<center>
<asp:Label Font-Bold="true" ID="lbl_batch" runat="server"></asp:Label>
<hr />
</center>
<asp:GridView ID="grd_Batch" AutoGenerateColumns="false" runat="server" DataKeyNames="Batch_id"
AllowPaging="true" PageSize="20" PagerSettings-Position="Bottom" PagerSettings-PageButtonCount="10"
Width="100%" CssClass="table table-bordered table-hover table-stripped table-condensed table-responsive"
OnRowEditing="grd_Batch_RowEditing" OnRowCancelingEdit="grd_Batch_RowCancelingEdit" OnRowDataBound="grd_Batch_RowDataBound"
OnRowUpdating="grd_Batch_RowUpdating" OnRowDeleting="grd_Batch_RowDeleting" OnRowCommand="grd_Batch_RowCommand">
<Columns>
<asp:TemplateField HeaderText="S.No.">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="TP ID" DataField="Training_Partner_id" NullDisplayText="AWT"
ReadOnly="true" />
<asp:BoundField HeaderText="KIA" DataField="Certifying_Agency_name" NullDisplayText="AWT"
ReadOnly="true" />
<asp:BoundField HeaderText="Course" DataField="Course_name" NullDisplayText="AWT"
ReadOnly="true" />
<%--New Code Add District on 24082021 --%>
<asp:TemplateField HeaderText="District">
<ItemTemplate>
<asp:Label ID="lbl_district" runat="server" Text='<%#Eval("District_Name") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddl_district" runat="server" DataTextField="District_Name" DataValueField="District_id"
Width="80px">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Batch Start Date">
<ItemTemplate>
<asp:Label ID="lbl_batchStartDate" runat="server" Text='<%#Eval("Batch_Start_date","{0:dd/MM/yyyy}") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txt_batchStartDate" runat="server" Text='<%#Eval("Batch_Start_date","{0:dd/MM/yyyy}") %>'
Width="80px">
</asp:TextBox>
<cc1:CalendarExtender ID="calExtenderBStartDate" runat="server" TargetControlID="txt_batchStartDate"
Format="dd/MM/yyyy">
</cc1:CalendarExtender>
<asp:RequiredFieldValidator ID="ReqBatchStarDate" runat="server" ControlToValidate="txt_batchStartDate"
ForeColor="Red" ValidationGroup="a" ErrorMessage="Enter batch start date !!"
SetFocusOnError="true">
</asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Batch End Date">
<ItemTemplate>
<asp:Label ID="lbl_batchendtDate" runat="server" Text='<%#Eval("Batch_End_Date","{0:dd/MM/yyyy}") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txt_batchendtDate" runat="server" Text='<%#Eval("Batch_End_Date","{0:dd/MM/yyyy}") %>'
Width="80px">
</asp:TextBox>
<cc1:CalendarExtender ID="calExtenderBSENdDate" runat="server" TargetControlID="txt_batchendtDate"
Format="dd/MM/yyyy">
</cc1:CalendarExtender>
<asp:RequiredFieldValidator ID="ReqBatcendDate" runat="server" ControlToValidate="txt_batchendtDate"
ForeColor="Red" ValidationGroup="a" ErrorMessage="Enter batch End date !!" SetFocusOnError="true">
</asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Proposed Exam Date">
<ItemTemplate>
<asp:Label ID="lbl_PurposeExamtDate" runat="server" Text='<%#Eval("purposedExamdate","{0:dd/MM/yyyy}") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txt_PurposeExamtDate" runat="server" Text='<%#Eval("purposedExamdate","{0:dd/MM/yyyy}") %>'
Width="80px">
</asp:TextBox>
<cc1:CalendarExtender ID="calExtender1Date" runat="server" TargetControlID="txt_PurposeExamtDate"
Format="dd/MM/yyyy">
</cc1:CalendarExtender>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Schedule Exam Date">
<ItemTemplate>
<asp:Label ID="lbl_ScheduleDate" runat="server" Text='<%#Eval("Scheduled_Exam_Date","{0:dd/MM/yyyy}") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox Enabled="true" ID="txt_ScheduleDate" runat="server" Text='<%#Eval("Scheduled_Exam_Date","{0:dd/MM/yyyy}") %>'
Width="80px">
</asp:TextBox>
<cc1:CalendarExtender ID="calExtender2Date" runat="server" TargetControlID="txt_ScheduleDate"
Format="dd/MM/yyyy">
</cc1:CalendarExtender>
</EditItemTemplate>
</asp:TemplateField>
<%--Start New Code Add on 14052020 Second and third Scheduled Date--%>
<asp:TemplateField HeaderText="Schedule Exam Date 2nd">
<ItemTemplate>
<asp:Label ID="lbl_ScheduleDate2" runat="server" Text='<%#Eval("SecondTimeAppearScheduledDate","{0:dd/MM/yyyy}") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox Enabled="true" ID="txt_ScheduleDate2" runat="server" Text='<%#Eval("SecondTimeAppearScheduledDate","{0:dd/MM/yyyy}") %>'
Width="80px">
</asp:TextBox>
<cc1:CalendarExtender ID="calExtender4Date" runat="server" TargetControlID="txt_ScheduleDate2"
Format="dd/MM/yyyy">
</cc1:CalendarExtender>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Schedule Exam Date 3rd">
<ItemTemplate>
<asp:Label ID="lbl_ScheduleDate3" runat="server" Text='<%#Eval("ThirdTimeAppearScheduledDate","{0:dd/MM/yyyy}") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox Enabled="true" ID="txt_ScheduleDate3" runat="server" Text='<%#Eval("ThirdTimeAppearScheduledDate","{0:dd/MM/yyyy}") %>'
Width="80px">
</asp:TextBox>
<cc1:CalendarExtender ID="calExtender5Date" runat="server" TargetControlID="txt_ScheduleDate3"
Format="dd/MM/yyyy">
</cc1:CalendarExtender>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BatchSize">
<ItemTemplate>
<asp:Label ID="lbl_batchsize" runat="server" Text='<%#Eval("Max_student_allowed") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txt_batchsize" MaxLength="2" runat="server" Text='<%#Eval("Max_student_allowed") %>'
Width="40px"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqmax" runat="server" ControlToValidate="txt_batchsize"
ValidationGroup="a" ErrorMessage="*" ForeColor="Red" SetFocusOnError="true">
</asp:RequiredFieldValidator>
<asp:RangeValidator runat="server" ID="txt_batchsize_range" Type="Integer" MaximumValue="30"
MinimumValue="1" ControlToValidate="txt_batchsize" ErrorMessage="1-30" ForeColor="Red"
SetFocusOnError="true" ValidationGroup="a">
</asp:RangeValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Batch Creation Date">
<ItemTemplate>
<asp:Label ID="lbl_BatchCreation" runat="server" Text='<%#Eval("createdDate","{0:dd/MM/yyyy}") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox Enabled="false" ID="txt_BatchCreation" runat="server" Text='<%#Eval("createdDate","{0:dd/MM/yyyy}") %>'
Width="80px">
</asp:TextBox>
<cc1:CalendarExtender ID="calExtender3Date" runat="server" TargetControlID="txt_BatchCreation"
Format="dd/MM/yyyy">
</cc1:CalendarExtender>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="BatchLocation" DataField="batchLocation" ReadOnly="true"
NullDisplayText="NA" ItemStyle-Wrap="true" />
<asp:TemplateField HeaderText="Attendance Upload">
<ItemTemplate>
<asp:LinkButton ID="Lnk_Attendance" runat="server" Text='Attendance' Visible='<%# Eval("REBD_Upload_AttendenceDOC").ToString() != "" ? true : false %>'
CommandArgument='<%#(Eval("REBD_Upload_AttendenceDOC")) %>' OnClick="Lnk_Attendance_Click"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:FileUpload ID="fld_AttendanceUpload" runat="server" Width="160px" />
<%--<asp:CustomValidator ID="CustomValidator2" runat="server" Display="Dynamic" ForeColor="Red"
ErrorMessage="" ValidationGroup="a" SetFocusOnError="true" OnServerValidate="CustomValidator2_ServerValidate"
ControlToValidate="fld_AttendanceUpload"></asp:CustomValidator> --%>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EDIT">
<ItemTemplate>
<asp:Button ID="btn_Edit" runat="server" Text="Edit" CommandName="Edit" CssClass="btn btn-primary" />
<%-- <asp:Button ID="btn_Delete" runat="server" OnClientClick="return confirm('Are you sure to delete this record ?')" Text="Delete" CommandName="Delete" CssClass="btn btn-danger" />
<asp:Button ID="btn_sucess" runat="server" OnClientClick="return confirm('Are you sure to Extend this batch ?')" Text="Extend" CommandName="Extend" CssClass="btn btn-success" />--%>
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="btn_update" ValidationGroup="a" runat="server" Text="Update" OnClientClick="return confirm('Are you sure to update this record ?');"
CommandName="Update" CssClass="btn btn-primary" />
<asp:Button ID="bhtn_cancel" runat="server" Text="Cancel" CommandName="Cancel" CssClass="btn btn-danger" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Extend">
<ItemTemplate>
<asp:LinkButton ID="lnkButton" runat="server" Text="Extend" CommandArgument='<%#Eval("Training_Partner_id") + "," + Eval("Certifying_Agency_name") + "," + Eval("Course_name") + "," + Eval("Batch_Start_date") + "," + Eval("Batch_End_Date")+ "," + Eval("batchLocation") %>'
CommandName="modal" CssClass="btn btn-success btn-sm"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:Button ID="btn_Delete" runat="server" OnClientClick="return confirm('Are you sure to delete this record ?')"
Text="Delete" CommandName="Delete" CssClass="btn btn-danger" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:Label ID="lblmsg" runat="server" />
<asp:Button ID="modelPopup" runat="server" Style="display: none" />
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="modelPopup"
PopupControlID="updatePanel" CancelControlID="btnCancel" BackgroundCssClass="tableBackground">
</cc1:ModalPopupExtender>
<asp:Panel ID="updatePanel" runat="server" BackColor="White" Width="60%" Style="display: none">
<table class="table table-bordered table-condensed table-stripped table-responsive"
cellspacing="4">
<tr style="background-color: #33CC66">
<td colspan="2" align="center">
Batch Details
</td>
</tr>
<tr>
<td>
Training Parnter ID:
</td>
<td>
<asp:Label ID="lbl_tpid" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
KIA Name:
</td>
<td>
<asp:Label ID="lbl_kia" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
Course Name:
</td>
<td>
<asp:Label ID="lbl_coourse" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
Batch Start Date:
</td>
<td>
<asp:Label ID="lbl_batchstartdate" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
Batch End Date:
</td>
<td>
<asp:Label ID="lbl_batchendate" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
Batch Location:
</td>
<td>
<asp:Label ID="lbl_batchlocation" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
Batch Code:
</td>
<td>
<asp:Label ID="lbl_batchCode_popup" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
No of Days Extend:
</td>
<td>
<asp:DropDownList ID="drp_days" CssClass="form-control" runat="server">
<asp:ListItem Text="--select day--" Value="0"></asp:ListItem>
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
<asp:ListItem Text="4" Value="4"></asp:ListItem>
<asp:ListItem Text="5" Value="5"></asp:ListItem>
<asp:ListItem Text="6" Value="6"></asp:ListItem>
<asp:ListItem Text="7" Value="7"></asp:ListItem>
<asp:ListItem Text="8" Value="8"></asp:ListItem>
<asp:ListItem Text="9" Value="9"></asp:ListItem>
<asp:ListItem Text="10" Value="10"></asp:ListItem>
<asp:ListItem Text="11" Value="11"></asp:ListItem>
<asp:ListItem Text="12" Value="12"></asp:ListItem>
<asp:ListItem Text="13" Value="13"></asp:ListItem>
<asp:ListItem Text="14" Value="14"></asp:ListItem>
<asp:ListItem Text="15" Value="15"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="req_days" ValidationGroup="po" runat="server" InitialValue="0"
ErrorMessage="Select Day" ForeColor="Red" ControlToValidate="drp_days" Display="Dynamic">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<label>
For all batch Extend</label>
</td>
<td>
<asp:CheckBox ID="chk_all" runat="server" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnUpdate" CommandName="Update" ValidationGroup="po" OnClientClick="return confirm('Are you sure to update ?');"
CssClass="btn btn-primary" runat="server" Text="Modify" OnClick="btnUpdate_Click" />
<asp:Button ID="btnCancel" CssClass="btn btn-danger" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
</asp:Content>
ASPX.CS PAGE
-----------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.IO;
public partial class View_Admin_Master_BatchUpdate : System.Web.UI.Page
{
BatchInformation obj = new BatchInformation();
protected void Page_Init(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
Browser.ClearBrowserData();
Page.ViewStateUserKey = Session.SessionID;
Response.Cache.SetValidUntilExpires(true);
}
string rno = null;
protected void CrossSiteRequestForgery()
{
//Code start for Cross Site Request Forgery
Random randomobj = new Random();
Session["randomno"] = randomobj.Next();
ViewState["CSRF"] = Session["randomno"].ToString();
//End Code
}
private void CreateRandomHashing()
{
Random rd = new Random();
Session["rnumb"] = rd.Next();
rno = Convert.ToString(Session["rnumb"]);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
CreateRandomHashing();
CrossSiteRequestForgery(); //To safe against CRSF attack
drp_state.Items.Clear();
drp_state.DataSource = obj.StateShow();
drp_state.DataTextField = "State_Name";
drp_state.DataValueField = "State_id";
drp_state.DataBind();
drp_state.Items.Insert(0, new ListItem("--Select State--", "0"));
}
}
protected void drp_state_SelectedIndexChanged(object sender, EventArgs e)
{
drp_batch.Items.Clear();
drp_TrainingPartner.Items.Clear();
DataTable dt = null;
try
{
dt = obj.TrainingParnterShow(drp_state.SelectedIndex > 0 ? Convert.ToInt32(drp_state.SelectedValue) : 0);
if (dt != null)
{
drp_TrainingPartner.DataSource = dt;
drp_TrainingPartner.DataTextField = "Tp_Name";
drp_TrainingPartner.DataValueField = "TP_ID";
drp_TrainingPartner.DataBind();
drp_TrainingPartner.Items.Insert(0, new ListItem("--select Training Parnter--", "0"));
}
else
{
drp_TrainingPartner.Items.Insert(0, new ListItem("--select Training Parnter--", "0"));
}
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
if (dt != null)
{
dt.Dispose();
}
}
}
protected void drp_TrainingPartner_SelectedIndexChanged(object sender, EventArgs e)
{
drp_batch.Items.Clear();
DataTable dt = null;
try
{
dt = obj.BatchShow(drp_TrainingPartner.SelectedIndex > 0 ? drp_TrainingPartner.SelectedValue : string.Empty);
if (dt != null)
{
drp_batch.DataSource = dt;
drp_batch.DataTextField = "Batch_Code";
drp_batch.DataValueField = "Batch_id";
drp_batch.DataBind();
drp_batch.Items.Insert(0, new ListItem("--select Training Parnter Batch--", "0"));
}
else
{
drp_batch.Items.Insert(0, new ListItem("--select Training Parnter Batch--", "0"));
}
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
if (dt != null)
{
dt.Dispose();
}
}
}
protected void drp_batch_SelectedIndexChanged(object sender, EventArgs e)
{
lbl_batch.Text = "";
DataTable dt = null;
try
{
dt = obj.BatchShowAll(drp_batch.SelectedIndex > 0 ? Convert.ToInt32(drp_batch.SelectedValue) : 0);
if (dt != null)
{
grd_Batch.DataSource = dt;
grd_Batch.DataBind();
lbl_batch.ForeColor = System.Drawing.Color.Blue;
lbl_batch.Text = "Total Number of Student Already Registered" + " " + obj.MaxStudentSize(drp_batch.SelectedIndex > 0 ? Convert.ToInt32(drp_batch.SelectedValue) : 0).ToString();
}
else
{
grd_Batch.DataSource = null;
grd_Batch.EmptyDataText = "Sorry no batch found..";
grd_Batch.EmptyDataRowStyle.HorizontalAlign = HorizontalAlign.Center;
grd_Batch.DataBind();
}
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
if (dt != null)
{
dt.Dispose();
}
}
}
protected void grd_Batch_RowEditing(object sender, GridViewEditEventArgs e)
{
grd_Batch.EditIndex = e.NewEditIndex;
drp_batch_SelectedIndexChanged(null, null);
}
protected void grd_Batch_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
grd_Batch.EditIndex = -1;
drp_batch_SelectedIndexChanged(null, null);
lbl_error.Text = string.Empty;
lbl_error.Visible = false;
}
protected void grd_Batch_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
if (ViewState["CSRF"] != null && Convert.ToString(ViewState["CSRF"]) == Convert.ToString(Session["randomno"]))
{
int? result = null;
int batchid = 0;
try
{
batchid = (int)(grd_Batch.DataKeys[e.RowIndex].Value);
var batchSdate = grd_Batch.Rows[e.RowIndex].FindControl("txt_batchStartDate") as TextBox;
var BatchEndDate = grd_Batch.Rows[e.RowIndex].FindControl("txt_batchendtDate") as TextBox;
//New Code Add District on 24082021
var Districtid = grd_Batch.Rows[e.RowIndex].FindControl("ddl_district") as DropDownList;
var purposedExamDate = grd_Batch.Rows[e.RowIndex].FindControl("txt_PurposeExamtDate") as TextBox;
var ScheduleExamDate = grd_Batch.Rows[e.RowIndex].FindControl("txt_ScheduleDate") as TextBox;
//New Code Add on 14052020
var SecondTimeAppearScheduledDate = grd_Batch.Rows[e.RowIndex].FindControl("txt_ScheduleDate2") as TextBox;
var ThirdTimeAppearScheduledDate = grd_Batch.Rows[e.RowIndex].FindControl("txt_ScheduleDate3") as TextBox;
var batchCreationDate = grd_Batch.Rows[e.RowIndex].FindControl("txt_BatchCreation") as TextBox;
var MaxBatchSize = grd_Batch.Rows[e.RowIndex].FindControl("txt_batchsize") as TextBox;
DateTime? purxamdate = null;
DateTime? schedulexamdate = null;
//New Code Add on 14052020
DateTime? secondtimeappearscheduleddate = null;
DateTime? thirdtimeappearscheduleddate = null;
DateTime? bSdate = null;
DateTime? bEdate = null;
DateTime? BcreateDate = null;
if (!string.IsNullOrEmpty(batchCreationDate.Text))
{
BcreateDate = DateTime.Parse(batchCreationDate.Text);
}
else
{
BcreateDate = null;
}
if (!string.IsNullOrEmpty(batchSdate.Text))
{
bSdate = DateTime.Parse(batchSdate.Text);
}
else
{
bSdate = null;
}
if (!string.IsNullOrEmpty(BatchEndDate.Text))
{
bEdate = DateTime.Parse(BatchEndDate.Text);
}
else
{
bEdate = null;
}
//purposedExamDate.Text != "" ? DateTime.Parse(purposedExamDate.Text) : null;
if (!string.IsNullOrEmpty(purposedExamDate.Text))
{
purxamdate = DateTime.Parse(purposedExamDate.Text);
}
else
{
purxamdate = null;
}
if (!string.IsNullOrEmpty(ScheduleExamDate.Text))
{
schedulexamdate = DateTime.Parse(ScheduleExamDate.Text);
}
else
{
schedulexamdate = null;
}
//New Code Add on 14052020
if (!string.IsNullOrEmpty(SecondTimeAppearScheduledDate.Text))
{
secondtimeappearscheduleddate = DateTime.Parse(SecondTimeAppearScheduledDate.Text);
}
else
{
secondtimeappearscheduleddate = null;
}
if (!string.IsNullOrEmpty(ThirdTimeAppearScheduledDate.Text))
{
thirdtimeappearscheduleddate = DateTime.Parse(ThirdTimeAppearScheduledDate.Text);
}
else
{
thirdtimeappearscheduleddate = null;
}
BatchInformation ob = new BatchInformation();
int maxstudentRegistered = ob.MaxStudentSize(batchid);//25
int currentbatchsize = Convert.ToInt32(MaxBatchSize.Text);//20
if (maxstudentRegistered <= currentbatchsize)
{
result = obj.BatchUpdate(batchid, Convert.ToInt32(Districtid.Text), bSdate, bEdate, purxamdate, schedulexamdate, BcreateDate, !string.IsNullOrEmpty(MaxBatchSize.Text) ? Convert.ToInt32(MaxBatchSize.Text) : 0);
USP_CA_SCHEDULE_EXAM_UPDATE_BATCH(batchid, null, null, secondtimeappearscheduleddate, thirdtimeappearscheduleddate, schedulexamdate, null, true, 1);
if (result.HasValue && result.Value > 0)
{
lbl_error.Visible = true;
lbl_error.ForeColor = System.Drawing.Color.Green;
lbl_error.Text = "Batch updated successfully";
//ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "alert('Batch updated sucessfully');", true);
}
else
{
lbl_error.Visible = true;
lbl_error.ForeColor = System.Drawing.Color.Red;
lbl_error.Text = "Batch Error";
}
}
else
{
grd_Batch.EditIndex = -1;
drp_batch_SelectedIndexChanged(null, null);
lbl_error.ForeColor = System.Drawing.Color.Red;
lbl_error.Visible = true;
lbl_error.Text = "Batch Size cannot decreased";
}
//Start New Code Add on 1052020 for Attendace Upload
int index = e.RowIndex;
GridViewRow row = (GridViewRow)grd_Batch.Rows[index];
FileUpload fld_AttendanceUpload = (FileUpload)row.FindControl("fld_AttendanceUpload");
string Upload_Attendance_Sheet_Document;
string ustring = Guid.NewGuid().ToString().Replace("-", "") + DateTime.Now.Ticks.ToString();
//Attendance Sheet Upload
if (fld_AttendanceUpload.HasFile)
{
string filename1 = Path.GetFileNameWithoutExtension(fld_AttendanceUpload.FileName);
string extension1 = Path.GetExtension(fld_AttendanceUpload.FileName);
Upload_Attendance_Sheet_Document = filename1 + "_" + ustring + extension1;
fld_AttendanceUpload.SaveAs(Server.MapPath("~\\View\\TrainingPartner\\StudentData\\Attendance\\" + Upload_Attendance_Sheet_Document));
UpdateAttendance(batchid, Upload_Attendance_Sheet_Document);
lbl_error.Visible = true;
lbl_error.ForeColor = System.Drawing.Color.Green;
lbl_error.Text = "Attendance Uploaded successfully";
}
else
{
return;
}
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
grd_Batch.EditIndex = -1;
drp_batch_SelectedIndexChanged(null, null);
CrossSiteRequestForgery();
CreateRandomHashing();
}
}
}
private int USP_CA_SCHEDULE_EXAM_UPDATE_BATCH(int Batchid, int? secondtime, int? thirdtime, DateTime? secondtimesched, DateTime? thirdtimesched, DateTime? scheduleexam, string Remarks, bool status, Int16 Flag)
{
int Res = 0;
try
{
Res = Luminious.DataAcessLayer.SqlHelper.ExecuteNonQuery(Luminious.Connection.Configuration.ConnectionString, CommandType.StoredProcedure, "USP_CA_SCHEDULE_EXAM_UPDATE_BATCH",
new SqlParameter[] {new SqlParameter("@BATCH_ID",Batchid) ,
new SqlParameter("@SecondTimeAppearBatch_ID",secondtime),
new SqlParameter("@ThirdTimeAppearBatc_ID",thirdtime),
new SqlParameter("@SecondTimeAppearScheduledDate",secondtimesched),
new SqlParameter("@ThirdTimeAppearScheduledDate",thirdtimesched),
new SqlParameter("@SCHEDULE_EXAM_DT",scheduleexam),
new SqlParameter("@Remark",Remarks) ,
new SqlParameter("@Status",status),
new SqlParameter("@Flag",Flag),
// new SqlParameter("@REBD_Upload_AttendenceDOC",REBD_Upload_AttendenceDOC)
});
}
catch (SqlException ee)
{
ExceptionHandler.WriteException(ee.Message);
}
catch (Exception ee)
{
ExceptionHandler.WriteException(ee.Message);
}
return Res;
}
protected void grd_Batch_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
if (ViewState["CSRF"] != null && Convert.ToString(ViewState["CSRF"]) == Convert.ToString(Session["randomno"]))
{
try
{
lbl_error.Text = string.Empty;
int Batchid = Convert.ToInt32(grd_Batch.DataKeys[e.RowIndex].Value);
BatchInformation obj = new BatchInformation();
int result = obj.BatchDelete(Batchid);
if (result > 0)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('Batch Deleted Successfully');", true);
drp_TrainingPartner_SelectedIndexChanged(null, null);
drp_batch_SelectedIndexChanged(null, null);
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('Error in batch delete');", true);
}
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
CrossSiteRequestForgery();
CreateRandomHashing();
}
}
}
protected void grd_Batch_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("modal") && e.CommandName != null)
{
if (e.CommandArgument != null && e.CommandArgument.ToString().Length > 0)
{
#region clearCntrol
drp_days.ClearSelection();
lbl_tpid.Text = string.Empty;
lbl_kia.Text = string.Empty;
lbl_coourse.Text = string.Empty;
lbl_batchstartdate.Text = string.Empty;
lbl_batchlocation.Text = string.Empty;
chk_all.Checked = false;
#endregion
string all = e.CommandArgument.ToString();
string[] arr = all.Split(',');
lbl_tpid.Text = !string.IsNullOrEmpty(arr[0].ToString()) ? arr[0] : "N/A";
lbl_kia.Text = !string.IsNullOrEmpty(arr[1]) ? arr[1] : "N/A";
lbl_coourse.Text = !string.IsNullOrEmpty(arr[2]) ? arr[2] : "N/A";
lbl_batchstartdate.Text = !string.IsNullOrEmpty(arr[3]) ? Convert.ToDateTime(arr[3]).ToLongDateString() : "N/A";
lbl_batchendate.Text = !string.IsNullOrEmpty(arr[4]) ? Convert.ToDateTime(arr[4]).ToLongDateString() : "N/A";
lbl_batchlocation.Text = !string.IsNullOrEmpty(arr[5]) ? arr[5] : "N/A";
lbl_batchCode_popup.Text = drp_batch.SelectedIndex > 0 ? drp_batch.SelectedItem.Text : "N/A";
}
this.ModalPopupExtender1.Show();
}
}
//New Code Add District on 24082021
protected void grd_Batch_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && grd_Batch.EditIndex == e.Row.RowIndex)
{
DropDownList ddl_district = (DropDownList)e.Row.FindControl("ddl_district");
DataTable dt = null;
try
{
dt = obj.DistrictShow(drp_state.SelectedIndex > 0 ? Convert.ToInt32(drp_state.SelectedValue) : 0);
if (dt != null)
{
ddl_district.DataSource = dt;
ddl_district.DataTextField = "District_Name";
ddl_district.DataValueField = "District_ID";
ddl_district.DataBind();
ddl_district.Items.Insert(0, new ListItem("--Select District--", "0"));
string selectedCity = DataBinder.Eval(e.Row.DataItem, "District_Name").ToString();
ddl_district.Items.FindByText(selectedCity).Selected = true;
}
else
{
ddl_district.Items.Insert(0, new ListItem("--Select District--", "0"));
}
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
if (dt != null)
{
dt.Dispose();
}
}
}
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
if (ViewState["CSRF"] != null && Convert.ToString(ViewState["CSRF"]) == Convert.ToString(Session["randomno"]))
{
try
{
if (chk_all.Checked)
{
if (Page.IsValid)
{
string SpName = "pro_batchExtendUpdate2";
SqlParameter[] para = { new SqlParameter("@dey", drp_days.SelectedIndex > 0 ? Convert.ToInt16(drp_days.SelectedValue) : 0) };
int rez = Luminious.DataAcessLayer.SqlHelper.ExecuteNonQuery(Luminious.Connection.Configuration.ConnectionString, CommandType.StoredProcedure, SpName, para);
if (rez > 0)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Batch duration updated successfully');", true);
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Batch Duration Update Error');", true);
}
}
}
else
{
if (Page.IsValid)
{
string SpName = "pro_batchExtendUpdate";
SqlParameter[] para = { new SqlParameter("@batchCode", !string.IsNullOrEmpty(lbl_batchCode_popup.Text) ? lbl_batchCode_popup.Text : null), new SqlParameter("@nofday", drp_days.SelectedIndex > 0 ? Convert.ToInt16(drp_days.SelectedValue) : 0) };
int rez = Luminious.DataAcessLayer.SqlHelper.ExecuteNonQuery(Luminious.Connection.Configuration.ConnectionString, CommandType.StoredProcedure, SpName, para);
if (rez > 0)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Batch duration updated successfully');", true);
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Batch Duration Update Error');", true);
}
}
}
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
CreateRandomHashing();
CrossSiteRequestForgery();
}
}
}
// New Code Add on 1052020 for Attendance
protected void Lnk_Attendance_Click(object sender, EventArgs e)
{
string Id = (sender as LinkButton).CommandArgument;
Response.Redirect("~\\View\\TrainingPartner\\StudentData\\Attendance\\" + Id);
}
public int UpdateAttendance(int BatchID, string REBD_Upload_AttendenceDOC)
{
int Resu = 0;
try
{
string UpdateQuery = @"Update T002_Request_ExamBatchDetails set REBD_Upload_AttendenceDOC=@REBD_Upload_AttendenceDOC, REBD_UpdatedOn=CURRENT_TIMESTAMP, REBD_UpdatedBy=@REBD_UpdatedBy where REBD_BatchID=@BATCH_ID";
SqlParameter[] para = {
new SqlParameter("@Batch_ID", BatchID),
new SqlParameter("@REBD_Upload_AttendenceDOC", REBD_Upload_AttendenceDOC),
new SqlParameter("@REBD_UpdatedBy", Convert.ToString(Session["adminsession"])),
};
Resu = Luminious.DataAcessLayer.SqlHelper.ExecuteNonQuery(Luminious.Connection.Configuration.ConnectionString, CommandType.Text, UpdateQuery, para);
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
return Resu;
}
}
public class BatchInformation:IDisposable
{
public DataTable StateShow()
{
DataTable dt = new DataTable();
dt = null;
try
{
string UserQ = @"select State_id,State_Name from MST_STATE where State_Status=1 order by State_Name";
dt = Luminious.DataAcessLayer.SqlHelper.ExecuteDataTable(Luminious.Connection.Configuration.ConnectionString, CommandType.Text, UserQ);
if (dt != null && dt.Rows.Count > 0)
{
return dt;
}
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
if (dt != null)
{
dt.Dispose();
}
}
return null;
}
public DataTable TrainingParnterShow(int StateID)
{
DataTable dt = new DataTable();
dt = null;
try
{
string UserQ = @"select TP_ID,Tp_Name from dbo.MST_TP_REGISTRATION where Tp_State=@Tp_State order by Tp_Name ";
dt = Luminious.DataAcessLayer.SqlHelper.ExecuteDataTable(Luminious.Connection.Configuration.ConnectionString, CommandType.Text, UserQ, new SqlParameter("@Tp_State", StateID));
if (dt != null && dt.Rows.Count > 0)
{
return dt;
}
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
if (dt != null)
{
dt.Dispose();
}
}
return null;
}
public DataTable BatchShow(string TPID)
{
DataTable dt = new DataTable();
dt = null;
try
{
string UserQ = @"select Batch_id,Batch_Code from MST_BATCH where RequestStatus=2 and Training_Partner_id=@Training_Partner_id";
dt = Luminious.DataAcessLayer.SqlHelper.ExecuteDataTable(Luminious.Connection.Configuration.ConnectionString, CommandType.Text, UserQ, new SqlParameter("Training_Partner_id", TPID));
if (dt != null && dt.Rows.Count > 0)
{
return dt;
}
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
if (dt != null)
{
dt.Dispose();
}
}
return null;
}
public DataTable BatchShowAll(int BatchID)
{
DataTable dt = new DataTable();
dt = null;
try
{
string UserQ = @"SELECT a.batchLocation, A.Batch_id, A.Max_student_allowed, A.Training_Partner_id,F.District_Name,A.Batch_Start_date,A.Batch_End_Date,A.purposedExamdate,E.Scheduled_Exam_Date,E.SecondTimeAppearScheduledDate,E.ThirdTimeAppearScheduledDate,A.createdDate,
B.Certifying_agency_name,C.Course_name,D.REBD_Upload_AttendenceDOC FROM MST_BATCH A
LEFT JOIN MST_CERTIFYING_AGENCY B ON A.Agency_id=B.Certifying_agency_id
LEFT JOIN MST_COURSE C ON A.Course_id=C.course_id
LEFT JOIN T002_Request_ExamBatchDetails D ON A.Batch_id=D.REBD_BatchID
LEFT JOIN CA_Scheduled_Exam E ON A.Batch_id=E.Batch_ID
LEFT JOIN MST_DISTRICT F ON A.District_id=F.District_Id
where A.RequestStatus=2 and A.Batch_id=@Batch_id";
dt = Luminious.DataAcessLayer.SqlHelper.ExecuteDataTable(Luminious.Connection.Configuration.ConnectionString, CommandType.Text, UserQ, new SqlParameter("@Batch_id", BatchID));
if (dt != null && dt.Rows.Count > 0)
{
return dt;
}
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
if (dt != null)
{
dt.Dispose();
GC.SuppressFinalize(this);
}
}
return null;
}
//New Code Add District on 24082021
public DataTable DistrictShow(int State_id)
{
DataTable dt = new DataTable();
dt = null;
try
{
string UserQ = @"select * from MST_District where State_id=@State_id";
dt = Luminious.DataAcessLayer.SqlHelper.ExecuteDataTable(Luminious.Connection.Configuration.ConnectionString, CommandType.Text, UserQ, new SqlParameter("@State_id", State_id));
if (dt != null && dt.Rows.Count > 0)
{
return dt;
}
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
if (dt != null)
{
dt.Dispose();
}
}
return null;
}
public int BatchDelete(int BatchID)
{
int result = 0;
try
{
result = Luminious.DataAcessLayer.SqlHelper.ExecuteNonQuery(Luminious.Connection.Configuration.ConnectionString, CommandType.StoredProcedure, "Pro_deleteBatchStudent", new System.Data.SqlClient.SqlParameter[] { new SqlParameter("@Batch_id", BatchID) });
return result;
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}
return result;
}
public int BatchUpdate(int Batchid, int Districtid, DateTime? BatchStartDate, DateTime? BatchEndDate, DateTime? purposedExamdate, DateTime? ScheduleExamDate, DateTime? BatchCreation, int MaxBatchsize)
{
int result = 0;
try
{
/*Batch_Start_date=ISNULL(@Batch_Start_date,Batch_Start_date),
Batch_End_Date=ISNULL(@Batch_End_Date,Batch_End_Date),
purposedExamdate=ISNULL(@purposedExamdate,purposedExamdate),
ScheduleExamDate=ISNULL(@ScheduleExamDate,ScheduleExamDate),
createdDate=ISNULL(@createdDate,createdDate),*/
// code update on 26092019
string UserQ = @"UPDATE MST_BATCH SET
Max_student_allowed=ISNULL(@Max_student_allowed,Max_student_allowed),
District_id=ISNULL(@District_id,District_id),
Batch_Start_Date=ISNULL(@Batch_Start_Date,Batch_Start_Date),
Batch_End_Date=ISNULL(@Batch_End_Date,Batch_End_Date),
purposedExamdate=ISNULL(@purposedExamdate,purposedExamdate),
ScheduleExamDate=ISNULL(@ScheduleExamDate,ScheduleExamDate)
where Batch_id=@Batch_id";
SqlParameter[] para = {
new SqlParameter("@Batch_Start_date",BatchStartDate),
new SqlParameter("@Batch_End_Date",BatchEndDate) ,
new SqlParameter("@purposedExamdate",purposedExamdate) ,
new SqlParameter("@ScheduleExamDate",ScheduleExamDate),
new SqlParameter("@createdDate",BatchCreation),
new SqlParameter("@Batch_id",Batchid),
new SqlParameter("@Max_student_allowed",MaxBatchsize),
//New Code Add District on 24082021
new SqlParameter("@District_id",Districtid)
};
result = Luminious.DataAcessLayer.SqlHelper.ExecuteNonQuery(Luminious.Connection.Configuration.ConnectionString, CommandType.Text, UserQ, para);
return result;
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
GC.SuppressFinalize(this);
}
return 0;
}
public int MaxStudentSize(int BatchID)
{
object ob = null;
try
{
string Q = "select COUNT(Batch_id) as 'Registered' from MST_STUDENT_REG where Batch_id=@Batch_id";
ob = Luminious.DataAcessLayer.SqlHelper.ExecuteScalar(Luminious.Connection.Configuration.ConnectionString, CommandType.Text, Q, new SqlParameter[] { new SqlParameter("@Batch_id", BatchID) });
if (ob != null)
{
return Convert.ToInt32(ob.ToString());
}
else
{
return 0;
}
}
catch (SqlException ex)
{
}
catch (Exception ex)
{
}
finally
{
if (ob != null)
{
ob = null;
}
}
return 0;
}
public void Dispose()
{
this.Dispose();
}
}
No comments:
Post a Comment