Archive

Archive for June, 2015

How To Find Sunday and Monday Between Two Dates Using C#

June 23, 2015 Leave a comment

Hi all,

Try this example to Find Sunday and Monday Between Two Dates Using C#


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="grd" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Key" HeaderText="Date" />
<asp:BoundField DataField="Value" HeaderText="Date" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>

In Code behind :


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DateTime StartingDate = DateTime.Parse("03/29/2008");
DateTime EndingDate = DateTime.Parse("04/30/2008");
Hashtable ht = new Hashtable();
foreach (DateTime date in GetDateRange(StartingDate, EndingDate))
{
if (date.DayOfWeek.ToString() == "Monday" || date.DayOfWeek.ToString() == "Sunday")
{

ht.Add(date.ToShortDateString(), date.DayOfWeek.ToString());
}
}
grd.DataSource = ht;
grd.DataBind();
}

private static List<DateTime> GetDateRange(DateTime StartingDate, DateTime EndingDate)
{
if (StartingDate > EndingDate)
{
return null;
}
List<DateTime> rv = new List<DateTime>();
DateTime tmpDate = StartingDate;
do
{
rv.Add(tmpDate);
tmpDate = tmpDate.AddDays(1);
} while (tmpDate <= EndingDate);
return rv;
}
}

Hope this helps

Good Luck.

Categories: ASP.Net

Display image Thumbnail from Database in GridView and Display Enlarged Popup in ASP.Net

June 12, 2015 Leave a comment

Hi all,

Try this example to Display image Thumbnail from Database in GridView and Display Enlarged Popup in ASP.Net

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js" type="text/javascript"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/Blitzer/jquery-ui.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
$('[id*=imgThumbnail]').bind('click', function () {
// $("#divImage").show();
$("[id*=imgBigImage]").attr('src', $(this).attr('alt'));
$("#divImage").dialog({
title: "Image",
modal: true,
resizable: false,
buttons: {
Close: function () {
$(this).dialog('close');
}
}
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_OnRowDataBound">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField HeaderText="File Path">
<ItemTemplate>
<asp:Image ID="imgThumbnail" AlternateText='<%# Eval("FilePath") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div id="divImage" style="display: none;">
<asp:Image ID="imgBigImage" runat="server" Width="300" Height="300" />
</div>
</form>
</body>
</html>

In Code behind :

protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("FilePath");
dt.Rows.Add("Jellyfish", "Images/Jellyfish.jpg");
dt.Rows.Add("Koala", "Images/Koala.jpg");
dt.Rows.Add("Penguins", "Images/Penguins.jpg");
dt.Rows.Add("Tulips", "Images/Tulips.jpg");
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}

protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
System.Web.UI.WebControls.Image img = e.Row.FindControl("imgThumbnail") as System.Web.UI.WebControls.Image;
string path = Server.MapPath(img.AlternateText);
img.ImageUrl = GenerateThumbnail(path);
}
}

private string GenerateThumbnail(string path)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(path);
using (System.Drawing.Image thumbnail = image.GetThumbnailImage(100, 100, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero))
{
using (MemoryStream memoryStream = new MemoryStream())
{
thumbnail.Save(memoryStream, ImageFormat.Png);
Byte[] bytes = new Byte[memoryStream.Length];
memoryStream.Position = 0;
memoryStream.Read(bytes, 0, (int)bytes.Length);
string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
return "data:image/png;base64," + base64String;
}
}
}

public bool ThumbnailCallback()
{
return false;
}

Hope this helps

Good Luck

Categories: ASP.Net, Javascript, Jquery

Disable Current and Past Dates in JQuery Calender

Hi all,

Try this example to disable current and past dates selection from JQuery Calender in ASP.Net

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Disable Current and Past Date</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script type="text/javascript">
$(function () {
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate()+1;
var currentYear = date.getFullYear();
$('#datepicker').datepicker({
minDate: new Date(currentYear, currentMonth, currentDate)
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>Date: <input type="text" id="datepicker" /></p>
</div>
</form>
</body>
</html>

Hope this helps

Good Luck.

Categories: ASP.Net, Javascript, Jquery

How to Implement jQuery UI Slider with ASP.NET

Hi all,

Try this example to Implement jQuery UI slider with ASP.NET

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Slider_Demo.aspx.cs" Inherits="Slider_Demo" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link type="text/css" rel="Stylesheet" href="http://ajax.microsoft.com/ajax/jquery.ui/1.8.5/themes/start/jquery-ui.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.ui/1.8.5/jquery-ui.min.js">
</script>
<title></title>
<script type="text/javascript">
$(document).ready(function () {
$("#slider").slider(
{
min: <%=MinValue%>,
max: <%=MaxValue%>,
step: <%=Step %>,
slide: function (event, ui) {
$("#txtValue").val(ui.value);
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="slider" style="width: 200px;">
</div>
<asp:TextBox ID="txtValue" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>

And In Code behind :


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Slider_Demo : System.Web.UI.Page
{
public const int MinValue = 0;
public const int MaxValue = 100;
public const int Step = 5;
protected void Page_Load(object sender, EventArgs e)
{

}
}

Hope this helps

Good Luck

Categories: ASP.Net, Jquery

Hide Export To Excel and Word Option from ReportViewer in ASP.Net

Hi all,

Try this example to Hide Export to Word and Excel Option from ReportViewer in ASP.Net

First Way :

 <style type="text/css">
a[title=Excel] {
display: none !important;
}
a[title=Word] {
display: none !important;
}
</style>

Second Way :

 <script type="text/javascript">
//-- To Hide ReportViewer Export to Word and Excel (Works)
window.onload = function () {
var formatDropDown = document.getElementById('ReportViewer1_ctl05_ctl04_ctl00_Menu');
var formats = formatDropDown.childNodes;
if (formatDropDown != null) {
formatDropDown.removeChild(formats[1]);
formatDropDown.removeChild(formats[2]);
}
}
</script>

Third Way :

 <script src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
//-- Another Way To Hide ReportViewer Export to Word and Excel (Works)
$(document).ready(function () {
$("a[title='Word']").parent().hide();
$("a[title='Excel']").parent().hide();
});
</script>

Hope this helps

Good Luck

Categories: ASP.Net