adsense

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