Adds

Thursday, 13 June 2013

Style GridView Using CSS in ASP.NET

GridView Code in aspx Page


<asp:GridView ID="grdvAttendance" runat="server" AutoGenerateColumns="False" GridLines="None"
        AllowPaging="true" CssClass="gridview" PagerStyle-CssClass="gridview_pager"
        AlternatingRowStyle-CssClass="gridview_alter" PageSize="5" OnPageIndexChanging="gridView_PageIndexChanging">
<AlternatingRowStyle CssClass="gridview_alter"></AlternatingRowStyle>
    <Columns>
        <asp:BoundField DataField="SlNo" HeaderText="Sl. No" Visible="false" />
        <asp:BoundField DataField="EmployeeID" HeaderText="Employee ID" />
        <asp:BoundField DataField="WorkingDate" DataFormatString="{0: MMM -dd, yyyy}" HeaderText="Date" />
        <asp:BoundField DataField="EmployeeInTime" HeaderText="In Time" />
        <asp:BoundField DataField="EmployeeOutTime" HeaderText="Out Time" />
        <asp:BoundField DataField="LateAttendance" HeaderText="L. A." />
        <asp:BoundField DataField="LateAttendanceDuration" HeaderText="Duration" />
        <asp:BoundField DataField="EarlyLeave" HeaderText="E. L." />
        <asp:BoundField DataField="EarlyLeaveDuration" HeaderText="Duration" />
        <asp:BoundField DataField="WorkingHours" HeaderText="Working Hours" />
        <asp:BoundField DataField="OverTime" HeaderText="O. T." />
        <asp:BoundField DataField="OverTimeDuration" HeaderText="Duration" />
    </Columns>
<PagerStyle CssClass="gridview_pager"></PagerStyle>
    </asp:GridView>
CSS Code to style the GridView

.gridview
{
    width: 100%;
    background-color: #fff;
    margin: 5px 0 10px 0;
    border: solid 1px #525252;
    border-collapse:collapse;
}
.gridview td
{
    padding: 2px;
    border: solid 1px #c1c1c1;
    color: #717171;
}
.gridview th
{
    padding: 4px 2px;
    color: #fff;
    background: #424242;
    border-left: solid 1px #525252;
    font-size: 0.9em;
}
.gridview .gridview_alter 
{
    background: #E7E7E7;
}
.gridview .gridview_pager 
{
    background: #424242;
}
.gridview .gridview_pager table 
{
    margin: 5px 0;
}
.gridview .gridview_pager td
{
    border-width: 0;
    padding: 0 6px;
    border-left: solid 1px #666;
    font-weight: bold;
    color: #fff;
    line-height: 12px;
 }  
.gridview .gridview_pager a 
{
    color: #666;
    text-decoration: none;
}
.gridview .gridview_pager a:hover 
{
    color: #000;
    text-decoration: none;
}
Output of the Gridview after Implement Style 

C# Custom GridView PageIndex / Pagination

Function for page index change (in aspx.cs page)

protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grdvAttendance.DataSource = a.GetAllByDate(Convert.ToDateTime(DateTime.Now.ToString("MMM-d, yyyy")));
            grdvAttendance.PageIndex = e.NewPageIndex;
            grdvAttendance.DataBind();
        }
 Call The Function in Gridview Control (in aspx page)


<asp:GridView ID="grdvAttendance" runat="server" AutoGenerateColumns="False"
        AllowPaging="true" PageSize="5" OnPageIndexChanging="gridView_PageIndexChanging">
</asp:GridView>

Get Unmatched Value Between Two Array In c#


Get Unmatched Value  Between Two Array In c#:


static void Main(string[] args)
        {
            var emp = new string[] { "Hasan", "Shohel", "Sajib", "Milan", "Saiful", "Shanta" };
            var att = new string[] { "Hasan", "Shohel", "Sajib" };

            var common = emp.Except(att);

            foreach (string s in common)
                Console.WriteLine(s);
            Console.ReadLine();
        }

Output:


For Match Value Just Use: Intersect.

                               var common = emp.Intersect(att);

 Output: 


 For All(Common &n Uncommon) value From Two Array Just Use: Union.
                                var common = emp.Union(att);

Output: 


 

Thursday, 6 June 2013

Clear All Text Box Using Loop without Using TextBox Name.

public void ClearAllTextBox(ControlCollection ctrls)
  {
            foreach (Control ctrl in ctrls)
            {
                if (ctrl is TextBox)
                    ((TextBox)ctrl).Text = string.Empty;
                ClearAllTextBox(ctrl.Controls);
            }
  }

Use the code below in click event

ClearAllTextBox(Page.Controls);

Tuesday, 4 June 2013

Insert only time to SQL Server using C# Entity Framework.

Database Tablecreate table Attendance
(
SLNo int IDENTITY(1,1),
EmployeeID varchar(20),
AttendanceDate date,
OfficeStartTime time,
OfficeEndTime time,
EmployeeLoginTime time,
EmployeeLogoutTime time,
WorkingHour int,
Comments varchar(10)
primary key(EmployeeID, AttendanceDate)


at.EmployeeLoginTime = TimeSpan.Parse(DateTime.Now.ToString("hh:mm:ss"));

In database time will store like 14:20:19

Monday, 3 June 2013

Create SQL Server Database Table With Two Primary Key.

create table Attendance
(
SLNo int IDENTITY(1,1),
EmployeeID varchar(20),
AttendanceDate date,
OfficeStartTime time,
OfficeEndTime time,
EmployeeLoginTime time,
EmployeeLogoutTime time,
WorkingHour int,
Comments varchar(10)
primary key(EmployeeID, AttendanceDate)
)