Archive

Archive for the ‘ASP.Net’ Category

JQuery calendar to display event data from Database

Hello,

Try this example to use JQuery calendar to display event data from Database


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

<!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">
<title></title>
	<link href="http://code.jquery.com/ui/1.9.2/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
 <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<style>
* {
margin: 0 auto;
padding: 0;
}

body {
background-color: #F2F2F2;
}

.container {
margin: 0 auto;
width: 920px;
padding: 50px 20px;
background-color: #fff;
}

h3 {
text-align: center;
}

#calendar {
margin-top: 40px;
}

.event a {
background-color: #42B373 !important;
background-image: none !important;
color: #ffffff !important;
}
</style>

<script type="text/javascript">
 var eventDates = {};
 $(function () {
 $.ajax({
 type: "POST",
 url: "Default2.aspx/GetEvents",
 data: '{}',
 contentType: "application/json; charset=utf-8",
 dataType: "json",
 success: OnSuccess,
 failure: function (response) {
 alert(response.d);
 },
 error: function (response) {
 alert(response.d);
 }
 });
 });

function OnSuccess(response) {
 $(response.d).each(function (i, e) {
 eventDates[convertDate(e.EventDate)] = convertDate(e.EventDate);
 });

$('#calendar').datepicker({
 beforeShowDay: function (date) {
 var highlight = eventDates[convertDate(date)];
 // alert(highlight);
 if (highlight) {
 return [true, "event", highlight];
 } else {
 return [true, '', ''];
 }
 }
 });
 }

function convertDate(inputFormat) {
 function pad(s) { return (s < 10) ? '0' + s : s; }
 var d = new Date(inputFormat);
 return [pad(d.getDate()), pad(d.getMonth() + 1), d.getFullYear()].join('/');
 }

</script>
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<h3>Highlight Particular Dates in JQuery UI Datepicker</h3>
<div id="calendar"></div>
</div>
</form>
</body>
</html>

In Code behind :


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

public partial class Default2 : System.Web.UI.Page
{
[WebMethod]
public static List<Event> GetEvents()
{
List<Event> events = new List<Event>();
events.Add(new Event()
{
EventID = 1,
EventName = "EventName 1",
EventDate = DateTime.Now.ToString("MM-dd-yyyy"),
EventDetail = string.Empty
});
events.Add(new Event()
{
EventID = 2,
EventName = "EventName 2",
EventDate = DateTime.Now.AddDays(4).ToString("MM-dd-yyyy"),
EventDetail = string.Empty
});
events.Add(new Event()
{
EventID = 3,
EventName = "EventName 3",
EventDate = DateTime.Now.AddDays(10).ToString("MM-dd-yyyy"),
EventDetail = string.Empty
});
events.Add(new Event()
{
EventID = 4,
EventName = "EventName 4",
EventDate = DateTime.Now.AddDays(22).ToString("MM-dd-yyyy"),
EventDetail = string.Empty
});
return events;
}

protected void Page_Load(object sender, EventArgs e)
{

}
}

Hope this helps

Good Luck.

Categories: ASP.Net, Jquery

Display Sum (Total) of Checked GridView Rows on CheckBox check using jQuery in ASP.Net

March 27, 2017 Leave a comment

Dears,

Try this example to Display Sum (Total) of Checked GridView Rows on CheckBox check using jQuery in ASP.Net

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
 <script type="text/javascript">
 $(function () {
 $('[id*=chk]').on('change', function () {
 var value = 0;
 $('[id*=chk]:checked').each(function () {
 var row = $(this).closest('tr');
 value = value + parseInt(row.find('[id*=lblValue]').html());
 });
 $('[id*=lblTotal]').html(value);
 });
 });
 </script>
<asp:GridView ID="gvData" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chk" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Values">
<ItemTemplate>
<asp:Label ID="lblValue" runat="server" Text='<%# Eval("Value") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Label ID="lblTotal" runat="server" />

In Code behind :

protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[1] { new DataColumn("Value", typeof(int)) });
dt.Rows.Add(10);
dt.Rows.Add(20);
dt.Rows.Add(30);
dt.Rows.Add(40);
gvData.DataSource = dt;
gvData.DataBind();
}
}

Hope this helps

Good Luck.

Categories: ASP.Net, Jquery

Convert Text in TextBox to Upper Using JavaScript

February 20, 2017 Leave a comment

Hi all,

Try this example to Convert Text in TextBox to Upper using Javascript

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
 function Capital(txt) {
 txt.value = txt.value.replace(/^\s+/, '').toUpperCase();
 }
 </script>
</head>
<body>
Enter Name:
<input type="text" value=" " onkeyup="Capital(this)" />
</body>
</html>

Hope this helps

Good Luck.

Categories: ASP.Net

Validate IBAN Using C#

January 5, 2017 Leave a comment

Hi all,

Try this example to Validate IBAN Using C#

public static bool ValidateBankAccount(string bankAccount)
{
bankAccount = bankAccount.ToUpper(); //IN ORDER TO COPE WITH THE REGEX BELOW
if (String.IsNullOrEmpty(bankAccount))
return false;
else if (System.Text.RegularExpressions.Regex.IsMatch(bankAccount, "^[A-Z0-9]"))
{
bankAccount = bankAccount.Replace(" ", String.Empty);
string bank =
bankAccount.Substring(4, bankAccount.Length - 4) + bankAccount.Substring(0, 4);
int asciiShift = 55;
StringBuilder sb = new StringBuilder();
foreach (char c in bank)
{
int v;
if (Char.IsLetter(c)) v = c - asciiShift;
else v = int.Parse(c.ToString());
sb.Append(v);
}
string checkSumString = sb.ToString();
int checksum = int.Parse(checkSumString.Substring(0, 1));
for (int i = 1; i < checkSumString.Length; i++)
{
int v = int.Parse(checkSumString.Substring(i, 1));
checksum *= 10;
checksum += v;
checksum %= 97;
}
return checksum == 1;
}
else
return false;
} 

Hope this helps

Good Luck

Categories: ASP.Net

Get Current Page Name

December 6, 2016 Leave a comment

Hi all,

Try this example to Get Current Page Name

public static string GetCurrentPageName()
{
string sPath = HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
string sRet = oInfo.Name;
return sRet;
}

Hope this helps

Good Luck.

Categories: ASP.Net

Validate Rad ComboBox

November 6, 2016 Leave a comment

Hi all,

Try this example to Validate Rad ComboBox Using ASP.Net Validation Controls


<script type="text/javascript">
 function validateddlType(source, args) {
 args.IsValid = false;
 var combo = $find("<%= ddlType.ClientID %>");
 var text = combo.get_text();
 if (text.length < 1) {
 args.IsValid = false;
 }
 else {
 var node = combo.findItemByText(text);
 if (node) {
 args.IsValid = true;
 }
 else {
 args.IsValid = false;
 }
 }
 }

</script>

<telerik:radcombobox id="ddlType" allowcustomtext="True" runat="server" emptymessage="--- Please Select ---" filter="Contains" skin="Telerik"></telerik:radcombobox>
<asp:RequiredFieldValidator ID="rfvType" ControlToValidate="ddlType" ForeColor="Red" runat="server" Display="Dynamic" ErrorMessage="Value is required" ValidationGroup="A"></asp:RequiredFieldValidator>
<asp:CustomValidator ID="cvType" ClientValidationFunction="validateddlType" ForeColor="Red" ControlToValidate="ddlType" ValidationGroup="A" runat="server" ErrorMessage="Please select a vaild Value"></asp:CustomValidator>

Hope this helps

Good Luck.

Categories: ASP.Net, Javascript

Display Images in RadioButtonList Control in ASP.NET

October 20, 2016 Leave a comment

Hi all,

Try this example to Display Images in RadioButtonList Control in ASP.NET

You can also check my previous posts

Bind RadioButtonList with Image from Database

Bind RadioButtonList to Image

Step 1: Create a new ASP.NET Web Application in Visual Studio. Add a folder in the root named Images. Right-click on the project name and select:

Add -> New Folder

Now add some images in this folder to show with RadioButtons in the RadioButtonList control. Right-click on the Images folder and select:

Add -> Existing Item

Application-Folder-in-ASP.NET.jpg

Step 2: Add a RadioButtonList in HTML source view of Default.aspx, as shown in the following:

<div>
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
BorderStyle="Groove" BorderWidth="1px" RepeatColumns="3" RepeatLayout="Table">
</asp:RadioButtonList>
</div>

RepeatColumns of RadioButtonList is set to “3” to divide its items in three columns. For example if we have 18 items in the RadioButtonList, it will be displayed in 3 columns with 6 RadioButtons in each column.
The RepeatLayout property is used to specify the arrangement of RadioButtons inside the RadioButtonList control. By default or when it is set to “Table”, RadioButtons are rendered in a table but if it is set to “Flow”, it is rendered without a table.

Step 3: Write the following code in the Page Load event of Default.aspx.cs:

protected void Page_Load(object sender, EventArgs e)
{
ListItem item;
int i = 0;
System.IO.FileInfo file;

var Images =
from n in System.IO.Directory.GetFiles(Server.MapPath("Images"))
orderby n descending
select n;

foreach (var filename in Images)
{
file = new System.IO.FileInfo(filename);

item = new ListItem("<img src='" + "Images/" + file.Name + "' alt='" + file.Name +
"' title='"+file.Name+"'/>", i.ToString());

RadioButtonList1.Items.Add(item);
RadioButtonList1.CellPadding = 5;
RadioButtonList1.CellSpacing = 5;
i++;
}
}

Hope this helps

Good Luck.

 

Categories: ASP.Net