Hi,
I am doing a leave application in which I want to display working days (dates) apart from holidays and weekends. So first I make sure that it is not a holiday by comparing with my holidaymaster table and not saturday or sunday.
my code so far looks like this
asp.net:
<
asp:GridViewID="grdWorkingDays"runat="server"AllowSorting="true"AutoGenerateColumns
="true"></asp:gridview>
c#:
DateTime LeaveStartDate = Convert
.ToDateTime(txtHRPeriodFrom.Text);
DateTime LeaveEndDate = Convert
.ToDateTime(txtHRPeriodTo.Text);
ArrayList List = newArrayList
();
//Display working days in a grid with an option for HR to allot PL/CL/CO
//Check whether it is a holiday(compare with holiday_master) or saturday or sunday
for (DateTime
i = LeaveStartDate; i <= LeaveEndDate; i = i.AddDays(1))
{
SqlConnection con = newSqlConnection(ConfigurationManager.AppSettings["connectionString"
]);
SqlCommand cmd = newSqlCommand
();
cmd.Connection = con;
con.Open();
//checking if the date is a holiday.
cmd.CommandText =
"select count(*) from holiday_master where CONVERT(varchar(10),dateofholiday,103)=convert(varchar(10),'" + i + "',103)"
;
int HolidayCheck = Convert
.ToInt32(cmd.ExecuteScalar());
cmd.CommandText =
"select datename(dw,convert(datetime,'" + i + "',103))";
// getting the day of the week
string
DayOfWeek = cmd.ExecuteScalar().ToString();
if (HolidayCheck == 0 || DayOfWeek.ToLower() != "saturday" || DayOfWeek.ToLower() != "sunday"
)
{
List.Add(i);
}
else
{
}
}
grdWorkingDays.DataSource = List;
grdWorkingDays.DataBind();
Now coming to the point, this code is showing all the dates including holidays in the grid.
Secondly, I want to display working days in one column anddropdown in the second column so that the HR can allot each day with a PL/CL/Comp. Off. how do we bind 2 columns to two different controls one to array list and other with a dropdown.
Kindly help me.
Thanks,
Srilatha.