Tuesday, July 9, 2013

SQL Server getdate in YYYY-MM-DD without time

If you ever wanted to get a date field without time? This is a common question that have been asked and there are several ways to get the desired result.

There are two options but you should select the best one to match your requirement

1) Get date without time part

 SELECT CONVERT(VARCHAR(12), GETDATE(), 23)

This will give the following output

2013-07-10

2) Get date with time part represented as zeros

SELECT CONVERT(datetime,CONVERT(char(10), GetDate(),126))
 
This one converts the result back to date time with the following output 
 
2013-07-10 00:00:00.000
 
Cheers
Samitha 
 

Thursday, June 27, 2013

Asp.net Gridview Adjust Row Height

When working with the Asp.net Gridview it is a common that we set a fixed height to the rows of the grid. But I came across a situation where height of the Gridview changes even if RowStyle and
AlternatingRowStyle is specified.

The solution seems to be bit tricky but it worked for me. As Boriss Pavlovs have suggested in the following post you will need to set the row height on page prerender event

        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (dgEvent.Rows.Count > 0)
                dgEvent.Height = new Unit(dgEvent.RowStyle.Height.Value * dgEvent.Rows.Count);
        }

http://stackoverflow.com/questions/13762220/how-to-set-fixed-width-and-height-for-grid-row-which-is-dynamically-generating-i

Cheers
Samitha

ASP.Net Clendar Hide WeekEnd

Asp.Net Calender control gives facility to hide the day cells by using the following code.

 e.Cell.Visible = !e.Day.IsWeekend;

Even though you can hide the day cell, Calender header will be still visible and it will show the Saturday and Sunday headings.

I have come across one post that would give some starting point to resolve this issues.

http://stackoverflow.com/questions/554111/how-can-i-hide-weekends-when-using-the-asp-net-calendar-control

As described in this post you will have to override the Calender control's render method to achieve the desired behavior. But this method did not work for me as it expects a XML compatible string.

In the same post as zacharydl have suggested I was able to achive the result using jQuery with a slight modification to the code. You will have to call the javascript function during the post back event to avoid showing the weekends when we change the selected month.

<script language="javascript">

 HideWeekEnd();
 
   
    function HideWeekEnd ()
    {
        $('._title').parent().attr('colspan', '7'); 
        $('.evenCal:nth-last-child(1) , .evenCal:nth-last-child(2) ', $('#ScheduleParentWeb_cpHolder_calSchedule')).hide(); // remove last two headings
        $('._weekendday').hide(); // remove all the cells marked weekends
    }

 Sys.Application.add_init(appl_init);

        function appl_init() {
            var pgRegMgr = Sys.WebForms.PageRequestManager.getInstance();
            pgRegMgr.add_endRequest(HideWeekEnd);// calls the  HideWeekEnd funtion on postback
        }

    </script>

<asp:Calendar runat="server" ID="Calendar1">
    <TitleStyle CssClass="_title" />
    <DayHeaderStyle CssClass="evenCal" />
    <WeekendDayStyle CssClass="_weekendday" />
</asp:Calendar>

Finally add the css classes to a stylesheet.

Cheers
Samitha

Sunday, June 23, 2013

javascript date comparison

A simple way to compara two date objects is to use the getTime() as shown below.

var d1 = new Date(2013, 6, 1);
var d2 = new Date(2013, 10, 1);
 
if (d1.getTime() > d2.getTime())
true;
else
false ;

cheers
Samitha

Tuesday, May 28, 2013

jQuery Easy UI

If you have ever dream of using a jquery grid and other tools , have a look at following url which provides bunch of jQuery supported controls. Worth a try..


http://www.jeasyui.com/demo/main/index.php

Cheers
Samitha

Thursday, May 9, 2013

Pass two arguments to DataNavigateUrlFormatString

Hyperlink Column in a Gridview can be easily accomadated to accept two or more arguments as displayed below.

 <asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”False” >
<Columns>

<asp:HyperLinkField DataNavigateUrlFields=”ProducrID,Company” DataNavigateUrlFormatString=”ProductDetails.aspx?ProducrID={0}&Company={1}” Text=”View Student” />
<asp:BoundField DataField=”Description” HeaderText=”Description"  />
</Columns>
</asp:GridView>   

Cheers
Samitha

Tuesday, April 23, 2013

use Session variable in an HttpHandler

In order to use session variables inside an  HttpHandler implement the IRequiresSessionState(System.Web.SessionState namespace) interface

E.g.
 public class AutoSuggest : IHttpHandler, IRequiresSessionState
{
   public void ProcessRequest(HttpContext context)
  {
      context.Session["session_name"] ="xyz";
   }
}

Cheers
Samitha.