Monday, 19 May 2014
Saturday, 17 May 2014
Text box has to allow only characters in Asp.Net
In Text box Design Coding:
Font-Names="Verdana" Font-Size="9pt" Height="18px" Width="190px"
MaxLength="50"></asp:TextBox>
Text box has to allow only characters:
function isNameKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if ((charCode <= 93 && charCode >= 65) || (charCode <= 122 && charCode >= 97){
return true;
}
else {
return false;
}
}
Text box has to allow only characters with Space:
function isNameKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if ((charCode <= 93 && charCode >= 65) || (charCode <= 122 && charCode >= 97) || (charCode == 32) ){
return true;
}
else {
return false;
}
}
Text box has to allow only numbers:
function isNumberKey1(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode < 48 || charCode > 57) {
return false;
}
else {
return true;
}
}
Text box has to allow only numbers with dots:
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode != 46 && (charCode < 48 || charCode > 57)) {
return false;
}
else {
return true;
}
}
jQuery - Allow Alphanumeric (Alphabets & Numbers)
Characters in Textbox using JavaScript
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Allow only alphanumeric characters in textbox</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function () {
$('#txtNumeric').keydown(function (e) {
if (e.shiftKey || e.ctrlKey || e.altKey) {
e.preventDefault();
} else {
var key = e.keyCode;
if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {
e.preventDefault();
}
}
});
});
</script>
</head>
<body>
<div>
<b>Enter Text:</b><input type="text" id="txtNumeric" />
</div>
</body>
</html>
Friday, 9 May 2014
In School Attendance Report For Month Wise
Design Page
Default.aspx.cs
int GetDaysInMonth(int month, int year)
{
if (month < 1 || month > 12)
{
throw new System.ArgumentOutOfRangeException("month", month, "month mustbe between 1 and 12");
}
if (1 == month || 3 == month || 5 == month || 7 == month || 8 == month || 10 == month || 12 == month)
{
return 31;
}
else if (2 == month)
{
if (0 == (year % 4))
{
if (0 == (year % 400))
{
return 29;
}
else if (0 == (year % 100))
{
return 28;
}
return 29;
}
return 28;
}
return 30;
}
protected void btnReport_Click(object sender, EventArgs e)
{
string bno = DrpBatchNo.SelectedValue.ToString().Trim();
string icode = DrpInsName.SelectedValue.ToString().Trim();
string year21 = txtYear.Text.ToString().Trim();
string month21 = DrpMonth.SelectedValue.ToString().Trim();
int year = 0;
if (year21 != "")
{
year = Convert.ToInt32(year21);
}
int month = 0;
if (month21 != "")
{
month = Convert.ToInt32(month21);
}
if (year21.Length == 4)
{
if ((bno != "All" || bno != "") && (icode != "All" || icode != ""))
{
//Check No Of Days
int days = GetDaysInMonth(Convert.ToInt32(DrpMonth.SelectedValue), Convert.ToInt32(txtYear.Text.ToString().Trim()));
//Create a DataTable
DataTable myDT = new DataTable();
for (int i = 1; i <= days; i++)
{
if (i == 1)
{
DataColumn id2 = new DataColumn("id");
//Create a First column Name
id2.ColumnName = "Member Code";
id2.MaxLength = 60;
myDT.Columns.Add(id2);
DataColumn id1 = new DataColumn("id");
//Create a First Second Name
id1.ColumnName = "Member Name";
id1.MaxLength = 60;
myDT.Columns.Add(id1);
}
// loop end after i < = days
DataColumn id = new DataColumn("id");
// i is a day 1 column until end of days
id.ColumnName = i.ToString("#00");
id.MaxLength = 4;
myDT.Columns.Add(id);
}
for (int i = 1; i <= 1; i++)
{
// This Datatable is used to select all members from member table
DataTable dt = TRN.RGetAttendance(bno);
if (dt.Rows.Count > 0)
{
for (int j = 0; j < dt.Rows.Count; j++)
{
DataRow dr = myDT.NewRow();
string name = dt.Rows[j][1].ToString();
string mcode = dt.Rows[j][0].ToString();
// single Member code until end of month days
for (int ii = 0; ii <= days + 1; ii++)
{
if (ii == 0)
{
dr[ii] = mcode;
}
if (ii == 1)
{
dr[ii] = name;
}
else if (ii > 1)
{
string attdate = (ii - 1).ToString("#00") + "/" + month.ToString("#00") + "/" + year.ToString("#0000");
string day1 = attdate.Substring(0, 2);
string month1 = attdate.Substring(3, 2);
string year1 = attdate.Substring(6, 4);
int day11 = 0;
int month11 = 0;
int year11 = 0;
if (day1 != "" && month1 != "" && year1 != "")
{
day11 = Convert.ToInt32(day1);
month11 = Convert.ToInt32(month1);
year11 = Convert.ToInt32(year1);
attdate = datetimeconvert(year11, month11, day11);
}
// This Datatable is used to select a data from member code
DataTable dt1 = TRN.RGetAttendance1(mcode, attdate);
if (dt1.Rows.Count > 0)
{
string status = dt1.Rows[0][3].ToString();
dr[ii] = status;
}
}
}
// add a name, code, no of days present or absent
myDT.Rows.Add(dr);
}
}
}
//Bind All rows in Gridview
GrdAttendance.DataSource = myDT;
GrdAttendance.DataBind();
}
else
{
ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('" + "Select Valid Institute and Batch Name" + "');</script>", false);
}
}
else
{
ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('" + "Enter a Valid Year" + "');</script>", false);
}
}
public static string datetimeconvert(int a, int b, int c)
{
string ye2 = Convert.ToString(a);
string mo2 = Convert.ToString(b);
string da2 = Convert.ToString(c);
if (mo2.Length == 1)
{
mo2 = "0" + mo2;
}
if (da2.Length == 1)
{
da2 = "0" + da2;
}
string[] allStr = new String[] { mo2, da2, ye2 };
string datetime = String.Join("/", allStr);
return datetime;
}
Table
CREATE TABLE [dbo].[attendance_dtl](
[attend_date] [smalldatetime] NULL,
[attend_time] [varchar](20) NULL,
[attend_membercode] [varchar](25) NULL,
[attend_status] [char](1) NULL,
[attend_batchno] [varchar](20) NULL,
[attend_institute_code] [int] NULL
)
Stored Procedure in Sql
CREATE PROCEDURE [dbo].[Sp_RGetAttendance]
@bno varchar(100)
AS
BEGIN
Select trainee_dtl.trainee_membercode, trainee_dtl.trainee_membername from trainee_dtl
where trainee_dtl.trainee_course_batchno = @bno
END
CREATE PROCEDURE [dbo].[Sp_RGetAttendance1]
@mcode varchar(100),
@attdate smalldatetime
AS
BEGIN
Select tnpvp_attendance_dtl.* from attendance_dtl
where attendance_dtl.attend_membercode = @mcode and attendance_dtl.attend_date = @attdate
END
Output
Example of XML with XSLT
In Books.xml
<?xml version="1.0"?>
<Books>
<Book>
<Title>Beginning XML</Title>
<Author>John</Author>
</Book>
<Book>
<Title>Mastering XML</Title>
<Author>Peter</Author>
</Book>
</Books>
In Books.xml
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Books">
<HTML>
<BODY>
<TABLE>
<TR>
<TD>Title</TD>
<TD>Author</TD>
</TR>
<xsl:for-each select="Book">
<TR>
<TD><xsl:value-of select="Title"/></TD>
<TD><xsl:value-of select="Author"/></TD>
</TR>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
In Default.aspx Page
Add Xml icon From the toolbox
In Default.aspx.cs Page
//coding type 1
string xmlPath = Server.MapPath("Books.xml");
string xsltPath = Server.MapPath("Books.xslt");
XmlReader objXMlReader = XmlReader.Create(xmlPath);
XslCompiledTransform objXSLCompTransform =
new XslCompiledTransform();
objXSLCompTransform.Load(xsltPath);
StringBuilder objStrBuil = new StringBuilder();
TextWriter objTextWri = new StringWriter(objStrBuil);
objXSLCompTransform.Transform(objXMlReader, null, objTextWri);
Literal1.Text = objStrBuil.ToString();
objXMlReader.Close();
(Or)
//coding type 2
Xml1.DocumentSource = Request.QueryString[0];
Xml1.TransformSource = Request.QueryString[1];
Output For Coding Type1
Output For Coding Type2
Subscribe to:
Posts (Atom)