==>>In this article I am posting how to rotate multiple div like a slide show . It's a basic functionality that is used mostly in various websites. So i explain how to rotate div In Asp .Net using JQuery.In the Previous Article post the New-Features-in-Visual-Studio-2013 will help you for increase knowledge .: -
First you Need to create a website that have a aspx page.
Then add a Div in the body that have multiple divs.
. Div
<div id="MainDv">
<div id="Div1" class="DvCss DvCssa">
div 1 Show now
</div>
<div id="Div2" class="DvCss">
div 2 Show now
</div>
<div id="Div3" class="DvCss">
div 3 Show now
</div>
</div>
After the add div in body need to write css and js .
Css.
<style type="text/css">
div
{
width: 100px;
height: 100px;
}
#MainDv
{
position: relative;
}
.DvCss
{
position: absolute;
top: 0;
left: 0;
display: none;
}
.DvCssa
{
display: block;
}
#Div1
{
background-color: Pink;
}
#Div2
{
background-color: Aqua;
}
#Div3
{
background-color: Fuchsia;
}
</style>
.JS
<script type="text/javascript" language="javascript">
$(window).load(function() {
var divs = $('.DvCss');
function fade() {
var current = $('.DvCssa');
var currentIndex = divs.index(current),
nextIndex = currentIndex + 1;
if (nextIndex >= divs.length) {
nextIndex = 0;
}
var next = divs.eq(nextIndex);
next.stop().fadeIn(2000, function() {
$(this).addClass('DvCssa');
});
current.stop().fadeOut(2000, function() {
$(this).removeClass('DvCssa');
setTimeout(fade, 2500);
});
}
fade();
})
</script>
.donot forgot add
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
'C# .NET ASP .NET,Grid View,DropDownList,AJAX,JavaScript,JQuery,asp.net articles,C#.NET Articles,ASP,ASP.NET,C#,VB,CSharp,C Sharp,dotnet,subhash jakhar,GridView,DropDownList,Visual Studio,ajax,Java Script,JQuery,XML,Crystal Reports,SSIS,SSRS,DetailsView,winforms,windows forms,windows application,code samples,.net code examples'
Tuesday, July 23, 2013
Monday, July 8, 2013
What's new features in Visual Studio 2013
==>>In this article I am posting What is New in Visual Studio 2013. In this version Microsoft bring various stuff either in tooling, core, service etc . So i explain the new features of .NET Framework 4.5.1 will help you for increase knowledge .: -
1. In this version MicrSoft include Edit & Continue during debugging in 64-bit
2. Return Value Inspection, In this features we can get the return value of a method when we debugging in auto windows and immediate window.
3. Improve the functionality of Async Debugging ,Call Stack and Task Window this is support Store Applications, Web Applications and Desktop Applications in Windows 8.1
4. This version provide reliable connection with Azure Database.
5. This version provide the functionality for make Automatically retry/reconnect broken connection
6. Good experience for connected devices
7. Colorize the icons in Solution Explorer
8. New design for Team Explorer
9. Scroll bar map mode
10. Browser Links,It is a good feature that provide functionality to IDE connected with the browser via SignalR hub
11. New HTML Editor
12. Improvment in JavaScript & CSS editor
13. In Java Script provide the
(i) Block-Scoped Variables (ii) Container Objects,
14. In the Code Features
(i) View Definition in popup
(ii) Enhanced Scroll-Bar Facility
15. 200+ bugs with high DPI monitors have been fixed with Visual Studio 2013, including how options are displayed.
16. Provide the functionality auto-complete braces, comments, and quotes has now also been included out of the box, meaning If we have open a curly brace and start writing without worrying about the ending brace. It adjust automacily.
17. Solutions will now be loaded async, meaning we are able to open solutions with 100+ projects, and they will open in the background allowing you to work on files while everything else loads. The files you last had open will load first allowing you to quickly resume where you left off.
18. Now in the new version the options menus can now be resized, so we are not restricted to the default size.
19. Now we are able choose the theme of your IDE (Blue, Dark, Black).
The various new thing carry by this new version If you want to try to use features of this version then download by Click Here.....
1. In this version MicrSoft include Edit & Continue during debugging in 64-bit
2. Return Value Inspection, In this features we can get the return value of a method when we debugging in auto windows and immediate window.
3. Improve the functionality of Async Debugging ,Call Stack and Task Window this is support Store Applications, Web Applications and Desktop Applications in Windows 8.1
4. This version provide reliable connection with Azure Database.
5. This version provide the functionality for make Automatically retry/reconnect broken connection
6. Good experience for connected devices
7. Colorize the icons in Solution Explorer
8. New design for Team Explorer
9. Scroll bar map mode
10. Browser Links,It is a good feature that provide functionality to IDE connected with the browser via SignalR hub
11. New HTML Editor
12. Improvment in JavaScript & CSS editor
13. In Java Script provide the
(i) Block-Scoped Variables (ii) Container Objects,
14. In the Code Features
(i) View Definition in popup
(ii) Enhanced Scroll-Bar Facility
15. 200+ bugs with high DPI monitors have been fixed with Visual Studio 2013, including how options are displayed.
16. Provide the functionality auto-complete braces, comments, and quotes has now also been included out of the box, meaning If we have open a curly brace and start writing without worrying about the ending brace. It adjust automacily.
17. Solutions will now be loaded async, meaning we are able to open solutions with 100+ projects, and they will open in the background allowing you to work on files while everything else loads. The files you last had open will load first allowing you to quickly resume where you left off.
18. Now in the new version the options menus can now be resized, so we are not restricted to the default size.
19. Now we are able choose the theme of your IDE (Blue, Dark, Black).
The various new thing carry by this new version If you want to try to use features of this version then download by Click Here.....
Monday, July 1, 2013
Price/Number convert into words in C# Asp .Net
==>> In this article I am posting how to convert Price/Number in words using c# Asp .Net. Some time we need convert Price/Number in words in banking /financial type application and in invoice report we need this so this post will heplfull for you.
For this you need take a new website and add a textbox,label and button then add the cs code given below : -
aspx Page Code:-
TextBox
<asp:TextBox ID="TxtPrice" runat="server" MaxLength="9"></asp:TextBox>
Button
<asp:Button ID="BtnConvert" runat="server" Text="Convert In Words" ValidationGroup="val"
onclick="BtnConvert_Click" />
Label
<asp:Label ID="LblPriceinWords" runat="server" BackColor="#ccffff" ></asp:Label>
aspx.cs Page Code:-
public static string AmountToWord(int number)
{
if (number == 0) return "Zero";
if (number == -2147483648)
return "Minus Two Hundred and Fourteen Crore Seventy Four Lakh Eighty Three Thousand Six Hundred and Forty Eight";
int[] num = new int[4];
int first = 0;
int u, h, t;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
if (number < 0)
{
sb.Append("Minus ");
number = -number;
}
string[] words0 = {"" ,"One ", "Two ", "Three ", "Four ",
"Five " ,"Six ", "Seven ", "Eight ", "Nine "};
string[] words1 = {"Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ",
"Fifteen ","Sixteen ","Seventeen ","Eighteen ", "Nineteen "};
string[] words2 = {"Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ",
"Seventy ","Eighty ", "Ninety "};
string[] words3 = { "Thousand ", "Lakh ", "Crore " };
num[0] = number % 1000; // units
num[1] = number / 1000;
num[2] = number / 100000;
num[1] = num[1] - 100 * num[2]; // thousands
num[3] = number / 10000000; // crores
num[2] = num[2] - 100 * num[3]; // lakhs
//You can increase as per your need.
for (int i = 3; i > 0; i--)
{
if (num[i] != 0)
{
first = i;
break;
}
}
for (int i = first; i >= 0; i--)
{
if (num[i] == 0) continue;
u = num[i] % 10; // ones
t = num[i] / 10;
h = num[i] / 100; // hundreds
t = t - 10 * h; // tens
if (h > 0) sb.Append(words0[h] + "Hundred ");
if (u > 0 || t > 0)
{
if (h == 0)
sb.Append("");
else
if (h > 0 || i == 0) sb.Append("and ");
if (t == 0)
sb.Append(words0[u]);
else if (t == 1)
sb.Append(words1[u]);
else
sb.Append(words2[t - 2] + words0[u]);
}
if (i != 0) sb.Append(words3[i - 1]);
}
return sb.ToString().TrimEnd() + " Rupees only";
}
protected void BtnConvert_Click(object sender, EventArgs e)
{
int price = Convert.ToInt32(TxtPrice.Text);
LblPriceinWords.Text = AmountToWord(price);
}
Example:-
Hpoe this will help you........
Download Sample Code :-
For this you need take a new website and add a textbox,label and button then add the cs code given below : -
aspx Page Code:-
TextBox
<asp:TextBox ID="TxtPrice" runat="server" MaxLength="9"></asp:TextBox>
Button
<asp:Button ID="BtnConvert" runat="server" Text="Convert In Words" ValidationGroup="val"
onclick="BtnConvert_Click" />
Label
<asp:Label ID="LblPriceinWords" runat="server" BackColor="#ccffff" ></asp:Label>
aspx.cs Page Code:-
public static string AmountToWord(int number)
{
if (number == 0) return "Zero";
if (number == -2147483648)
return "Minus Two Hundred and Fourteen Crore Seventy Four Lakh Eighty Three Thousand Six Hundred and Forty Eight";
int[] num = new int[4];
int first = 0;
int u, h, t;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
if (number < 0)
{
sb.Append("Minus ");
number = -number;
}
string[] words0 = {"" ,"One ", "Two ", "Three ", "Four ",
"Five " ,"Six ", "Seven ", "Eight ", "Nine "};
string[] words1 = {"Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ",
"Fifteen ","Sixteen ","Seventeen ","Eighteen ", "Nineteen "};
string[] words2 = {"Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ",
"Seventy ","Eighty ", "Ninety "};
string[] words3 = { "Thousand ", "Lakh ", "Crore " };
num[0] = number % 1000; // units
num[1] = number / 1000;
num[2] = number / 100000;
num[1] = num[1] - 100 * num[2]; // thousands
num[3] = number / 10000000; // crores
num[2] = num[2] - 100 * num[3]; // lakhs
//You can increase as per your need.
for (int i = 3; i > 0; i--)
{
if (num[i] != 0)
{
first = i;
break;
}
}
for (int i = first; i >= 0; i--)
{
if (num[i] == 0) continue;
u = num[i] % 10; // ones
t = num[i] / 10;
h = num[i] / 100; // hundreds
t = t - 10 * h; // tens
if (h > 0) sb.Append(words0[h] + "Hundred ");
if (u > 0 || t > 0)
{
if (h == 0)
sb.Append("");
else
if (h > 0 || i == 0) sb.Append("and ");
if (t == 0)
sb.Append(words0[u]);
else if (t == 1)
sb.Append(words1[u]);
else
sb.Append(words2[t - 2] + words0[u]);
}
if (i != 0) sb.Append(words3[i - 1]);
}
return sb.ToString().TrimEnd() + " Rupees only";
}
protected void BtnConvert_Click(object sender, EventArgs e)
{
int price = Convert.ToInt32(TxtPrice.Text);
LblPriceinWords.Text = AmountToWord(price);
}
Example:-
Hpoe this will help you........
Download Sample Code :-
Show Hide div using JQuery in asp .net
==>> In this article I am posting how to show and hide div using JQuery. Some time we need to hide and show div for show hide information on page so this post will heplfull for you.
.ASPX Code.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#show").click(function() {
$(".mydiv").show(1000);
});
$("#hide").click(function() {
$(".mydiv").hide(1000);
});
});
</script>
<title>Show-Hide div using JQuery</title>
<style type="text/css">
.mydiv
{
margin:10px;padding:12px;
border:2px solid #666;
width:100px;
height:100px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="mydiv">
This is test div
</div>
<input id="show" type="button" value="Show" />
<input id="hide" type="button" value="Hide" />
</form>
</body>
</html>
Show-Hide div using JQuery
.ASPX Code.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#show").click(function() {
$(".mydiv").show(1000);
});
$("#hide").click(function() {
$(".mydiv").hide(1000);
});
});
</script>
<title>Show-Hide div using JQuery</title>
<style type="text/css">
.mydiv
{
margin:10px;padding:12px;
border:2px solid #666;
width:100px;
height:100px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="mydiv">
This is test div
</div>
<input id="show" type="button" value="Show" />
<input id="hide" type="button" value="Hide" />
</form>
</body>
</html>
DEMO:-
Show Hide test div
Friday, June 21, 2013
Get highest and lowest salary of an employee using Top,MAX and CTE in SQLServer
==>> One of most interview question Get highest and lowest salary of an employee using Top and without Top ,Using Max without Max. So I am posting the all solution for get salary according question :----
EMP table:
SELECT * FROM dbo.EMP ORDER BY Salary
For Get 3rd Highest Salary :
SELECT TOP 1 EName,salary FROM (SELECT DISTINCT TOP 3 EName,salary FROM dbo.EMP ORDER BY Salary DESC) a ORDER BY salary ASC
For Get 3rd Lowest Salary
SELECT TOP 1 EName,salary FROM(SELECT DISTINCT TOP 3 EName,salary FROM emp ORDER BY Salary ASC ) a ORDER BY salary DESC
EMP table:
SELECT * FROM dbo.EMP ORDER BY Salary
Query for Get 3rd Highest and 3rd Lowest Salary using TOP Keyword in Sql Server
For Get 3rd Highest Salary :
SELECT TOP 1 EName,salary FROM (SELECT DISTINCT TOP 3 EName,salary FROM dbo.EMP ORDER BY Salary DESC) a ORDER BY salary ASC
For Get 3rd Lowest Salary
SELECT TOP 1 EName,salary FROM(SELECT DISTINCT TOP 3 EName,salary FROM emp ORDER BY Salary ASC ) a ORDER BY salary DESC
Query for Get 2rd Highest using MAX in Sql Server
SELECT MAX(Salary) as Salary
FROM dbo.EMP
WHERE Salary NOT IN ( SELECT MAX(Salary)
FROM dbo.EMP ) ;
Query for Get Nth Highest and Nth Lowest salary using CTE in Sql Server
WITH Salaries
AS ( SELECT Salary ,
EName ,
ROW_NUMBER() OVER ( ORDER BY Salary ASC ) AS 'RowNum'
FROM dbo.EMP
)
SELECT Salary ,
EName
FROM Salaries
WHERE RowNum = 5So in this way can select value using different-2 manner.The best way you can use CTE and find Nth number Value from table.
Hope thei post will helpfull.....
Delete Remove duplicate records or rows in sql server
==>> Some time we need Delete or Remove the duplicate rows in sql server this type of problem when occur our data table does not contain any primary
key column because of that it contains duplicate records that would be like
this:----
:- For get duplicate records you need to run this query this query return how many records are multiple The RowNumber column indicate the number of rows .......
SQLQuery:-
WITH tempTable as
(
SELECT ROW_NUMBER() Over(PARTITION BY EName,dptName ORDER BY EName) As RowNumber,* FROM dbo.EMP
)
SELECT * FROM tempTable
Result:-
:-Now You See we having the two row are multiple in RowNumber column greater then 1 mean the row in this table exist more then one time.
Now we need to execute another query for unique value from datatable for that we need write sql query like :-----
SQLQuery:-
WITH tempTable as
(
SELECT ROW_NUMBER() Over(PARTITION BY EName,dptName ORDER BY EName) As RowNumber,* FROM EMP
)
DELETE FROM tempTable where RowNumber >1
SELECT * FROM EMP order by EId asc
Result:-
So in this way we can remove the duplicate rows from sql table .
Hope this will help you for find your solution.
:- For get duplicate records you need to run this query this query return how many records are multiple The RowNumber column indicate the number of rows .......
SQLQuery:-
WITH tempTable as
(
SELECT ROW_NUMBER() Over(PARTITION BY EName,dptName ORDER BY EName) As RowNumber,* FROM dbo.EMP
)
SELECT * FROM tempTable
Result:-
:-Now You See we having the two row are multiple in RowNumber column greater then 1 mean the row in this table exist more then one time.
Now we need to execute another query for unique value from datatable for that we need write sql query like :-----
SQLQuery:-
WITH tempTable as
(
SELECT ROW_NUMBER() Over(PARTITION BY EName,dptName ORDER BY EName) As RowNumber,* FROM EMP
)
DELETE FROM tempTable where RowNumber >1
SELECT * FROM EMP order by EId asc
Result:-
So in this way we can remove the duplicate rows from sql table .
Hope this will help you for find your solution.
Query for Delete All tables,procedures,views,function from database in SQL Server
==>> In this article I am posting SQL Query for Delete All tables,procedures,views,function from database in SQL Server. Some time we need to Delete All tables,procedures,views,function from database in SQL Server so this query will heplfull.
--For Delete Tables
DECLARE @Sql NVARCHAR(500)
DECLARE @Cursor CURSOR
SET
@Cursor = CURSOR FAST_FORWARD FOR
SELECT DISTINCT sql = 'ALTER TABLE [' + tc2.TABLE_NAME + '] DROP [' + rc1.CONSTRAINT_NAME + ']'
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc1
LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc2 ON tc2.CONSTRAINT_NAME =rc1.CONSTRAINT_NAME
OPEN @Cursor
FETCH NEXT FROM @Cursor INTO @Sql
WHILE ( @@FETCH_STATUS = 0 )
BEGIN
EXEC SP_EXECUTESQL @Sql
FETCH NEXT FROM @Cursor INTO @Sql
END
CLOSE @Cursor
DEALLOCATE @Cursor
GO
EXEC sp_MSForEachTable 'DROP TABLE ?'
GO
--For Delete Procedures
GO
DECLARE @procName VARCHAR(500)
DECLARE cur CURSOR
FOR SELECT [name] FROM sys.objects WHERE type = 'p'
OPEN cur
FETCH NEXT FROM cur INTO @procName
WHILE @@fetch_status = 0
BEGIN
IF @procName <> 'DeleteAllProcedures'
EXEC('drop procedure ' + @procName)
FETCH NEXT FROM cur INTO @procName
END
CLOSE cur
DEALLOCATE cur
--For Delete Views
GO
DECLARE @procName VARCHAR(500)
DECLARE cur CURSOR
FOR SELECT [name] FROM sys.objects WHERE type = 'v'
OPEN cur
FETCH NEXT FROM cur INTO @procName
WHILE @@fetch_status = 0
BEGIN
EXEC('drop view ' + @procName)
FETCH NEXT FROM cur INTO @procName
END
CLOSE cur
DEALLOCATE cur
--For Delete functions
GO
DECLARE @procName VARCHAR(500)
DECLARE cur CURSOR
FOR SELECT [name] FROM sys.objects WHERE type = 'fn'
OPEN cur
FETCH NEXT FROM cur INTO @procName
WHILE @@fetch_status = 0
BEGIN
EXEC('drop function ' + @procName)
FETCH NEXT FROM cur INTO @procName
END
CLOSE cur
DEALLOCATE cur
--For Delete Tables
DECLARE @Sql NVARCHAR(500)
DECLARE @Cursor CURSOR
SET
@Cursor = CURSOR FAST_FORWARD FOR
SELECT DISTINCT sql = 'ALTER TABLE [' + tc2.TABLE_NAME + '] DROP [' + rc1.CONSTRAINT_NAME + ']'
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc1
LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc2 ON tc2.CONSTRAINT_NAME =rc1.CONSTRAINT_NAME
OPEN @Cursor
FETCH NEXT FROM @Cursor INTO @Sql
WHILE ( @@FETCH_STATUS = 0 )
BEGIN
EXEC SP_EXECUTESQL @Sql
FETCH NEXT FROM @Cursor INTO @Sql
END
CLOSE @Cursor
DEALLOCATE @Cursor
GO
EXEC sp_MSForEachTable 'DROP TABLE ?'
GO
--For Delete Procedures
GO
DECLARE @procName VARCHAR(500)
DECLARE cur CURSOR
FOR SELECT [name] FROM sys.objects WHERE type = 'p'
OPEN cur
FETCH NEXT FROM cur INTO @procName
WHILE @@fetch_status = 0
BEGIN
IF @procName <> 'DeleteAllProcedures'
EXEC('drop procedure ' + @procName)
FETCH NEXT FROM cur INTO @procName
END
CLOSE cur
DEALLOCATE cur
--For Delete Views
GO
DECLARE @procName VARCHAR(500)
DECLARE cur CURSOR
FOR SELECT [name] FROM sys.objects WHERE type = 'v'
OPEN cur
FETCH NEXT FROM cur INTO @procName
WHILE @@fetch_status = 0
BEGIN
EXEC('drop view ' + @procName)
FETCH NEXT FROM cur INTO @procName
END
CLOSE cur
DEALLOCATE cur
--For Delete functions
GO
DECLARE @procName VARCHAR(500)
DECLARE cur CURSOR
FOR SELECT [name] FROM sys.objects WHERE type = 'fn'
OPEN cur
FETCH NEXT FROM cur INTO @procName
WHILE @@fetch_status = 0
BEGIN
EXEC('drop function ' + @procName)
FETCH NEXT FROM cur INTO @procName
END
CLOSE cur
DEALLOCATE cur
SQL Query for get all tables name and table rows
==>> In this article I am posting SQL Query for get all tables name and table rows. Some time we need to get all table name and it's rows so this query will heplfull.
SELECT scs.name + '.' + tas.name TableNames ,
SUM(pas.rows) RowsCounted
FROM sys.tables tas
INNER JOIN sys.partitions pas ON pas.OBJECT_ID = tas.OBJECT_ID
INNER JOIN sys.schemas scs ON tas.schema_id = scs.schema_id
WHERE tas.is_ms_shipped = 0
AND pas.index_id IN ( 1, 0 )
GROUP BY scs.name ,
tas.name
ORDER BY SUM(pas.rows) DESC
Hope this post will help you...
SELECT scs.name + '.' + tas.name TableNames ,
SUM(pas.rows) RowsCounted
FROM sys.tables tas
INNER JOIN sys.partitions pas ON pas.OBJECT_ID = tas.OBJECT_ID
INNER JOIN sys.schemas scs ON tas.schema_id = scs.schema_id
WHERE tas.is_ms_shipped = 0
AND pas.index_id IN ( 1, 0 )
GROUP BY scs.name ,
tas.name
ORDER BY SUM(pas.rows) DESC
Hope this post will help you...
Thursday, June 20, 2013
User Defined Function in Sql Server
==>> In this article I am going for taking about User Defined Function .It's type,use with example.
Users can create their own functions and make use of it inside T-SQL statements in system
in system database or in user defined database.
Three types of user-defined functions : -
value defined in function by the user.
*For Example we use EMP table here.
SELECT * FROM dbo.EMP ORDER BY EID
In this table we select the all record from the EMP table Now we apply all function on this table.
Now can create a UDF Scalar Function in this way:-
Create FUNCTION GetEmpNameLocation
(
@FirstName VARCHAR(50),
@Location VARCHAR(50)
)
RETURNS VARCHAR(101)
AS
BEGIN
RETURN (SELECT @FirstName+' '+@Location );
END
output:-
SELECT dbo.GetEmpNameLocation(EName,Location) AS Name ,Salary FROM dbo.EMP
So you can see we get the result Name with adding location of EMP.
2. Inline Table-Valued Functions
User defined inline table-valued function Return a set of rows as TABLE data type. The
value of table variable should be derived from a single SELECT statement.
Create a Inline Table-Valued Function
Create function fnGetEmp()
returns Table
AS
RETURN (SELECT * from dbo.EMP)
Output:-
Select * from fnGetEmp()
So in this way we can use Inline Table-Valued Function. It return table data type in single select statement.
3. Multistatement Table-Valued Functions
Returns a set of rows as TABLE data type. Unlike Inline Table-Valued function. In this
table variable must be explicitly declared and defined whose value can be derived from a
multiple sql statements.
Create a Multistatement Table-Valued Functions
Create function fnGetMulEmp()
returns @Emplpyee Table
(
EID int,
EmpName varchar(50),
Salary int
)
As
begin
Insert @Emplpyee Select EID,EName,Salary from Emp;
--Update Operation
update @Emplpyee set Salary=25000 where EID=1;
--Update only in @Emplpyee table not in the Main Emp table
return
end
Output:-
Select * from fnGetMulEmp()
SELECT * FROM dbo.EMP
In the result image you see in the table get by using Multistatement Table-Valued Functions updated salary but affected on Main table.
Note:-
Hope this will help you.
Users can create their own functions and make use of it inside T-SQL statements in system
in system database or in user defined database.
Three types of user-defined functions : -
- Scalar Functions
- Inline Table-Valued Functions
- Multistatement Table-Valued Functions .
- Scalar Functions
value defined in function by the user.
*For Example we use EMP table here.
SELECT * FROM dbo.EMP ORDER BY EID
In this table we select the all record from the EMP table Now we apply all function on this table.
Now can create a UDF Scalar Function in this way:-
Create FUNCTION GetEmpNameLocation
(
@FirstName VARCHAR(50),
@Location VARCHAR(50)
)
RETURNS VARCHAR(101)
AS
BEGIN
RETURN (SELECT @FirstName+' '+@Location );
END
output:-
SELECT dbo.GetEmpNameLocation(EName,Location) AS Name ,Salary FROM dbo.EMP
So you can see we get the result Name with adding location of EMP.
2. Inline Table-Valued Functions
User defined inline table-valued function Return a set of rows as TABLE data type. The
value of table variable should be derived from a single SELECT statement.
Create a Inline Table-Valued Function
Create function fnGetEmp()
returns Table
AS
RETURN (SELECT * from dbo.EMP)
Output:-
Select * from fnGetEmp()
So in this way we can use Inline Table-Valued Function. It return table data type in single select statement.
3. Multistatement Table-Valued Functions
Returns a set of rows as TABLE data type. Unlike Inline Table-Valued function. In this
table variable must be explicitly declared and defined whose value can be derived from a
multiple sql statements.
Create a Multistatement Table-Valued Functions
Create function fnGetMulEmp()
returns @Emplpyee Table
(
EID int,
EmpName varchar(50),
Salary int
)
As
begin
Insert @Emplpyee Select EID,EName,Salary from Emp;
--Update Operation
update @Emplpyee set Salary=25000 where EID=1;
--Update only in @Emplpyee table not in the Main Emp table
return
end
Output:-
Select * from fnGetMulEmp()
SELECT * FROM dbo.EMP
In the result image you see in the table get by using Multistatement Table-Valued Functions updated salary but affected on Main table.
Note:-
- Function returns only single value.
- Function can be nested up to 32 level.UDF can not returns XML Data Type.
- Function accepts only input parameters.
- UDF does not support Exception handling.
- Function can not perform Insert, Update, Delete on table table.
- UDF can have upto 1023 input parameters while a Stored Procedure can have upto 2100 input parameters.
Hope this will help you.
RowNumber in Select Query in Sql Server
==>> In this article I am posting how we can fatch record from sql with Row Number this is common issue with many developer . It is really very simple So first i select the whole EMP table
SELECT * FROM EMP
We use in built function ROW_NUMBER for get RowID in select Command so see how we apply ROW_NUMBER in select command and get row number on EMP Table : -
SELECT ROW_NUMBER() OVER (ORDER BY EID DESC) AS 'RowID',* FROM dbo.EMP
Now you can see first column RowID add in the result.now we perform many operations on on this table basis on RowID .
Now we try to fetch the record according to RowID column that the benefits of ROW_NUMBER Column
SELECT B.RowID ,
A.*
FROM dbo.EMP A
INNER JOIN ( SELECT ROW_NUMBER() OVER ( ORDER BY EID DESC ) AS 'RowID' ,
*
FROM dbo.EMP
) B ON A.EID = B.EID
AND B.RowID BETWEEN 5 AND 8
ORDER BY RowID
Now you can see the record from RowID 5 to 8 showing below .
Hope this post would be helpful. Keep Reading.
SELECT * FROM EMP
We use in built function ROW_NUMBER for get RowID in select Command so see how we apply ROW_NUMBER in select command and get row number on EMP Table : -
SELECT ROW_NUMBER() OVER (ORDER BY EID DESC) AS 'RowID',* FROM dbo.EMP
Now you can see first column RowID add in the result.now we perform many operations on on this table basis on RowID .
Now we try to fetch the record according to RowID column that the benefits of ROW_NUMBER Column
SELECT B.RowID ,
A.*
FROM dbo.EMP A
INNER JOIN ( SELECT ROW_NUMBER() OVER ( ORDER BY EID DESC ) AS 'RowID' ,
*
FROM dbo.EMP
) B ON A.EID = B.EID
AND B.RowID BETWEEN 5 AND 8
ORDER BY RowID
Now you can see the record from RowID 5 to 8 showing below .
Hope this post would be helpful. Keep Reading.
Thursday, May 9, 2013
Asp .Net File Upload validate file extension using JavaScript
==>> In this article I am posting how we can validate Asp .NET file upload control for file extension using Java Script. for this we need create a java script function...
JAVA SCRIPT FUNCTION:-
function validateExtensipon() {
var arrayExt = ['pdf', 'doc', 'docx', 'txt', 'xlsx', 'ppt', 'zip'];
var FilesVale = document.getElementById("FileUpload1");
var Ext = FilesVale.value.substring(FilesVale.value.lastIndexOf('.') + 1).toLowerCase();
if (arrayExt.indexOf(Ext) <= -1) {
alert("Upload only pdf,doc,zip,txt.xlsx and ppt extension flle");
return false;
}
else {
alert("File Upload Successfully..........")
}
}
This is the function that we have used for check extension of file
Aspx Page Code
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
function validateExtensipon() {
var arrayExt = ['pdf', 'doc', 'docx', 'txt', 'xlsx', 'ppt', 'zip'];
var FilesVale = document.getElementById("FileUpload1");
var Ext = FilesVale.value.substring(FilesVale.value.lastIndexOf('.') + 1).toLowerCase();
if (arrayExt.indexOf(Ext) <= -1) {
alert("Upload only pdf,doc,zip,txt.xlsx and ppt extension flle");
return false;
}
else {
alert("File Upload Successfully..........")
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
<br />
</div>
<asp:Button ID="Button1" runat="server" Text="Upload" OnClientClick="return validateExtensipon();" />
</form>
</body>
</html>
Download sample code
JAVA SCRIPT FUNCTION:-
function validateExtensipon() {
var arrayExt = ['pdf', 'doc', 'docx', 'txt', 'xlsx', 'ppt', 'zip'];
var FilesVale = document.getElementById("FileUpload1");
var Ext = FilesVale.value.substring(FilesVale.value.lastIndexOf('.') + 1).toLowerCase();
if (arrayExt.indexOf(Ext) <= -1) {
alert("Upload only pdf,doc,zip,txt.xlsx and ppt extension flle");
return false;
}
else {
alert("File Upload Successfully..........")
}
}
This is the function that we have used for check extension of file
Aspx Page Code
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
function validateExtensipon() {
var arrayExt = ['pdf', 'doc', 'docx', 'txt', 'xlsx', 'ppt', 'zip'];
var FilesVale = document.getElementById("FileUpload1");
var Ext = FilesVale.value.substring(FilesVale.value.lastIndexOf('.') + 1).toLowerCase();
if (arrayExt.indexOf(Ext) <= -1) {
alert("Upload only pdf,doc,zip,txt.xlsx and ppt extension flle");
return false;
}
else {
alert("File Upload Successfully..........")
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
<br />
</div>
<asp:Button ID="Button1" runat="server" Text="Upload" OnClientClick="return validateExtensipon();" />
</form>
</body>
</html>
Download sample code
Friday, April 26, 2013
Delegate in C#
==>>A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked. Unlike function pointers in C or C++, delegates are object-oriented, type-safe, and secure..
==>>A Delegate is a special type function means it can point to those function which are having identical signature with delegate.
you can also call delegate as a interface of methods as this acts same as interface in c# but that implemented for classes and this is implemented for methods..
* Step to create a delegate:
1 . Declaration
2. Instantiation
3. Invocation
* Why we need Delegate.......
You take a new console application in visual studio and write the sample code in cs file:---
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
public delegate string MyDelegate();//Declaration
public class TestDelegat
{
public string TestMethod()
{
return "This is Delegate Sample Program in C#.";
}
}
class Program
{
static void Main(string[] args)
{
TestDelegat TD = new TestDelegat();
MyDelegate MDel = new MyDelegate(TD.TestMethod);//Insatantiation
Console.Write("Output: " + MDel());//Invocation
}
}
}
first we define a delegate name with its signature,in this case its return type is string and no arguments. then we create instance of delegate which is MyDelegate now this can point to (reference to) all those function which having same signature as in our case function is TestMethod() and at the last we invoke this and receive this in message.
The main advantage of delegate is multi cast ...
*For use multi cast we need write this code
In The Class..
public void TestMethodMulticast()
{
console.write("Multicast");
}
and in the Static Void Main
MyDelegate TD= null;
TD+= new MyDelegate (TD.TestMethod);
TD+= new MyDelegate (TD.TestMethodMulticast);
Hope this post will help you for find your solution
Happy Coding
==>>A Delegate is a special type function means it can point to those function which are having identical signature with delegate.
you can also call delegate as a interface of methods as this acts same as interface in c# but that implemented for classes and this is implemented for methods..
* Step to create a delegate:
1 . Declaration
2. Instantiation
3. Invocation
* Why we need Delegate.......
- We can call many of method by single delegate no need of writ many of function.
- We set up event based system easily.
- We can calling many method that in different but having same signature.
- We can passing in parameter field a function.
- we can use select method.
You take a new console application in visual studio and write the sample code in cs file:---
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
public delegate string MyDelegate();//Declaration
public class TestDelegat
{
public string TestMethod()
{
return "This is Delegate Sample Program in C#.";
}
}
class Program
{
static void Main(string[] args)
{
TestDelegat TD = new TestDelegat();
MyDelegate MDel = new MyDelegate(TD.TestMethod);//Insatantiation
Console.Write("Output: " + MDel());//Invocation
}
}
}
first we define a delegate name with its signature,in this case its return type is string and no arguments. then we create instance of delegate which is MyDelegate now this can point to (reference to) all those function which having same signature as in our case function is TestMethod() and at the last we invoke this and receive this in message.
The main advantage of delegate is multi cast ...
*For use multi cast we need write this code
In The Class..
public void TestMethodMulticast()
{
console.write("Multicast");
}
and in the Static Void Main
MyDelegate TD= null;
TD+= new MyDelegate (TD.TestMethod);
TD+= new MyDelegate (TD.TestMethodMulticast);
Hope this post will help you for find your solution
Happy Coding
Thursday, April 18, 2013
Get Selected Value on Dropdownlist selectedindexchanged event using JQuery
==>> In this post I explain how Get Selected Value on
Dropdownlist selectedindexchanged event using JQuery this is help
us for get value of dropdown without any page post back in asp .net
We use the change event in the JQuery for get value of dropdown
on Dropdownlist selectedindexchanged event in JQuery
In the JQuery we write code like :-
<script type="text/javascript">
$(document).ready(function() {
$('#ddlName').change(function() {
$("#lName").text($("#ddlName option:selected").text());
$("#lValue").text($("#ddlName").val());
return false;
})
});
</script>
.ASPX Page Code:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Get Selected Value on Dropdownlist selectedindexchanged event using JQuery
</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#ddlName').change(function() {
$("#lName").text($("#ddlName option:selected").text());
$("#lValue").text($("#ddlName").val());
return false;
})
});
</script>
</head>
<body>
<form id="form1" runat="server">
<table width="50%">
<tr>
<td align="right">
Select Name:
</td>
<td>
<select id="ddlName" onchange="GetName()" runat="server">
<option value="0">Select</option>
<option value="1">Subhash</option>
<option value="2">Rakesh</option>
<option value="3">Satendra</option>
<option value="4">Raju</option>
<option value="5">Sachin</option>
</select>
</td>
</tr>
<tr>
<td align="right" style="font-family: Century Gothic; font-size: 12pt; color: Black">
Selected Name:-
</td>
<td>
<b>
<label id="lName" style="font-family: Century Gothic; font-size: 12pt; color: Aqua" />
</b>
</td>
</tr>
<tr>
<td align="right" style="font-family: Century Gothic; font-size: 12pt; color: Black">
Selected Name value:-
</td>
<td>
<b>
<label id="lValue" style="font-family: Century Gothic; font-size: 12pt; color: Aqua" />
</b>
</td>
</tr>
</table>
</form>
</body>
</html>
DEMO:-
Get Selected Value on Dropdownlist selectedindexchanged event using JQuery
We use the change event in the JQuery for get value of dropdown
on Dropdownlist selectedindexchanged event in JQuery
In the JQuery we write code like :-
<script type="text/javascript">
$(document).ready(function() {
$('#ddlName').change(function() {
$("#lName").text($("#ddlName option:selected").text());
$("#lValue").text($("#ddlName").val());
return false;
})
});
</script>
.ASPX Page Code:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Get Selected Value on Dropdownlist selectedindexchanged event using JQuery
</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#ddlName').change(function() {
$("#lName").text($("#ddlName option:selected").text());
$("#lValue").text($("#ddlName").val());
return false;
})
});
</script>
</head>
<body>
<form id="form1" runat="server">
<table width="50%">
<tr>
<td align="right">
Select Name:
</td>
<td>
<select id="ddlName" onchange="GetName()" runat="server">
<option value="0">Select</option>
<option value="1">Subhash</option>
<option value="2">Rakesh</option>
<option value="3">Satendra</option>
<option value="4">Raju</option>
<option value="5">Sachin</option>
</select>
</td>
</tr>
<tr>
<td align="right" style="font-family: Century Gothic; font-size: 12pt; color: Black">
Selected Name:-
</td>
<td>
<b>
<label id="lName" style="font-family: Century Gothic; font-size: 12pt; color: Aqua" />
</b>
</td>
</tr>
<tr>
<td align="right" style="font-family: Century Gothic; font-size: 12pt; color: Black">
Selected Name value:-
</td>
<td>
<b>
<label id="lValue" style="font-family: Century Gothic; font-size: 12pt; color: Aqua" />
</b>
</td>
</tr>
</table>
</form>
</body>
</html>
DEMO:-
Get Selected Value on Dropdownlist selectedindexchanged event using JavaScript
==>> In this post I explain how Get Selected Value on Dropdownlist selectedindexchanged event using JavaScript this is help us for get value of dropdown without any page post back in asp .net
We use the onchange event in the java script for get value of dropdown
on Dropdownlist selectedindexchanged event in JavaScript
In the java script we write code like :-
<script type="text/javascript">
function GetName() {
var name = document.getElementById("ddlName");
var strname = name.options[name.selectedIndex].text;
document.getElementById('lName').innerHTML = strname;
document.getElementById('lValue').innerHTML = name.options[name.selectedIndex].value;
}
</script>
.ASPX Page Code:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Get Selected Value on Dropdownlist selectedindexchanged event using JavaScript</title>
<script type="text/javascript">
function GetName() {
var name = document.getElementById("ddlName");
var strname = name.options[name.selectedIndex].text;
document.getElementById('lName').innerHTML = strname;
document.getElementById('lValue').innerHTML = name.options[name.selectedIndex].value;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table width="50%">
<tr>
<td align="right">
Select Name:
</td>
<td>
<asp:DropDownList ID="ddlName" runat="server" onchange="GetName()">
<asp:ListItem Text="Select" Value="0" />
<asp:ListItem Text="Subhash" Value="1" />
<asp:ListItem Text="Rakesh" Value="2" />
<asp:ListItem Text="Satendra" Value="3" />
<asp:ListItem Text="Raju" Value="4" />
<asp:ListItem Text="Sachin" Value="5" />
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="right" style="font-family: Century Gothic; font-size: 12pt; color: Black">
Selected Name:-
</td>
<td>
<b>
<label id="lName" style="font-family: Century Gothic; font-size: 12pt; color: Aqua" />
</b>
</td>
</tr>
<tr>
<td align="right" style="font-family: Century Gothic; font-size: 12pt; color: Black">
Selected Name value:-
</td>
<td>
<b>
<label id="lValue" style="font-family: Century Gothic; font-size: 12pt; color: Aqua"/>
</b>
</td>
</tr>
</table>
</form>
</body>
</html>
Get Selected Value on Dropdownlist selectedindexchanged event using JavaScript
We use the onchange event in the java script for get value of dropdown
on Dropdownlist selectedindexchanged event in JavaScript
In the java script we write code like :-
<script type="text/javascript">
function GetName() {
var name = document.getElementById("ddlName");
var strname = name.options[name.selectedIndex].text;
document.getElementById('lName').innerHTML = strname;
document.getElementById('lValue').innerHTML = name.options[name.selectedIndex].value;
}
</script>
.ASPX Page Code:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Get Selected Value on Dropdownlist selectedindexchanged event using JavaScript</title>
<script type="text/javascript">
function GetName() {
var name = document.getElementById("ddlName");
var strname = name.options[name.selectedIndex].text;
document.getElementById('lName').innerHTML = strname;
document.getElementById('lValue').innerHTML = name.options[name.selectedIndex].value;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table width="50%">
<tr>
<td align="right">
Select Name:
</td>
<td>
<asp:DropDownList ID="ddlName" runat="server" onchange="GetName()">
<asp:ListItem Text="Select" Value="0" />
<asp:ListItem Text="Subhash" Value="1" />
<asp:ListItem Text="Rakesh" Value="2" />
<asp:ListItem Text="Satendra" Value="3" />
<asp:ListItem Text="Raju" Value="4" />
<asp:ListItem Text="Sachin" Value="5" />
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="right" style="font-family: Century Gothic; font-size: 12pt; color: Black">
Selected Name:-
</td>
<td>
<b>
<label id="lName" style="font-family: Century Gothic; font-size: 12pt; color: Aqua" />
</b>
</td>
</tr>
<tr>
<td align="right" style="font-family: Century Gothic; font-size: 12pt; color: Black">
Selected Name value:-
</td>
<td>
<b>
<label id="lValue" style="font-family: Century Gothic; font-size: 12pt; color: Aqua"/>
</b>
</td>
</tr>
</table>
</form>
</body>
</html>
Tuesday, April 16, 2013
Async File Upload control example in C# asp.net to upload files to server using Ajax
==>> In this post I explain how to use Ajax AsyncFileUpload file upload in C# Asp .Net and showing progress bar when file uploading and confirmation message of Success and Fail
1 AsyncFileUpload works within the Update Panel
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
1. ASPX PAGE CODE:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>***Ajax Files Uploader Sample***</title>
<script type="text/javascript">
function uploadSuccess() {
document.getElementById('<%=lblMsg.ClientID %>').innerHTML = "Your File Uploaded Successfully";
}
function uploadFail() {
document.getElementById('<%=lblMsg.ClientID %>').innerHTML = "Your File upload Failed.";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ajax:ToolkitScriptManager ID="scriptManager1" runat="server" />
<div>
<ajax:AsyncFileUpload ID="AjaxSamplefileUpload" OnClientUploadComplete="uploadSuccess"
OnClientUploadError="uploadFail" CompleteBackColor="White" Width="350px" runat="server"
UploaderStyle="Modern" UploadingBackColor="#CCFFFF" ThrobberID="imgLoading" OnUploadedComplete="fileUploadSuccess" />
<br />
<asp:Image ID="imgLoading" runat="server" ImageUrl="loading.gif" />
<br />
<asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
AsyncFileUpload Events, Properties and Methods :-
Events
2. ASPX.CS PAGE CODE:-
using System;
using System.Threading;
using System.Web.UI;
using AjaxControlToolkit;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void fileUploadSuccess(object sender, AsyncFileUploadEventArgs e)
{
Thread.Sleep(1000);
string FileName = System.IO.Path.GetFileName(AjaxSamplefileUpload.FileName);
AjaxSamplefileUpload.SaveAs(Server.MapPath("Store/") + FileName);
}
}
Download sample code
AsyncFileUpload Control Features:--
1 AsyncFileUpload works within the Update Panel
2 AsyncFileUpload uploads the file without any postback
3 AsyncFileUpload provides Client Side and Server side events
4 There are different coloring options for showing file upload. As for example, it shows green color if upload is successful, otherwise it shows red if there is unsuccessful upload.
5 You can show the loading image while file uploading is in progress.
First you need install AJAX ,create a website add a folder name 'Store' After that you need add AjaxControlToolkit reference to your website add the line in your aspx page that given below......
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
1. ASPX PAGE CODE:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>***Ajax Files Uploader Sample***</title>
<script type="text/javascript">
function uploadSuccess() {
document.getElementById('<%=lblMsg.ClientID %>').innerHTML = "Your File Uploaded Successfully";
}
function uploadFail() {
document.getElementById('<%=lblMsg.ClientID %>').innerHTML = "Your File upload Failed.";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ajax:ToolkitScriptManager ID="scriptManager1" runat="server" />
<div>
<ajax:AsyncFileUpload ID="AjaxSamplefileUpload" OnClientUploadComplete="uploadSuccess"
OnClientUploadError="uploadFail" CompleteBackColor="White" Width="350px" runat="server"
UploaderStyle="Modern" UploadingBackColor="#CCFFFF" ThrobberID="imgLoading" OnUploadedComplete="fileUploadSuccess" />
<br />
<asp:Image ID="imgLoading" runat="server" ImageUrl="loading.gif" />
<br />
<asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
AsyncFileUpload Events, Properties and Methods :-
Events
- UploadedComplete :- Fired on the server side when the file successfully uploaded.
- UploadedFileError :- Fired on the server side when the uloaded file is corrupted.
- CompleteBackColor:- The control's background color on upload complete. Default value - 'Lime'.
- ContentType :- Gets the MIME content type of a file sent by a client.
- ErrorBackColor :- The control's background color on upload error. Default value - 'Red'.
- FileContent :- Gets a Stream object that points to an uploaded file to prepare for reading the contents of the file.
- FileName :- Gets the name of a file on a client to upload using the control.
- HasFile :- Gets a bool value indicating whether the control contains a file.
- OnClientUploadComplete :- The name of a javascript function executed in the client-side after the file successfully uploaded
- OnClientUploadError :- The name of a javascript function executed in the client-side if the file uploading failed.
- OnClientUploadStarted :-The name of a javascript function executed in the client-side on the file uploading started.
- ThrobberID :- ID of control that is shown while the file is uploading.
- UploaderStyle :- The control's appearance 2 style Traditional and Modern. Default value - 'Traditional'.
- SaveAs(string filename) - Saves the contents of an uploaded file.
2. ASPX.CS PAGE CODE:-
using System;
using System.Threading;
using System.Web.UI;
using AjaxControlToolkit;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void fileUploadSuccess(object sender, AsyncFileUploadEventArgs e)
{
Thread.Sleep(1000);
string FileName = System.IO.Path.GetFileName(AjaxSamplefileUpload.FileName);
AjaxSamplefileUpload.SaveAs(Server.MapPath("Store/") + FileName);
}
}
Download sample code
Thursday, April 11, 2013
Asp.Net Textbox Readonly using JQuery
==>> In this post i want to make asp .net text box read only
using JQuery .Some time we need this type of functionality in your
website so you can easily implement in your website just copy paste
blow code on your aspx page :----
1. ASPX PAGE CODE:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Asp.Net Textbox Readonly using JQuery</title>
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#<%=txtBoxName.ClientID%>').attr('readonly', true);
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtBoxName" runat="server" />
</div>
</form>
</body>
</html>
Hope this will help you...
1. ASPX PAGE CODE:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Asp.Net Textbox Readonly using JQuery</title>
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#<%=txtBoxName.ClientID%>').attr('readonly', true);
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtBoxName" runat="server" />
</div>
</form>
</body>
</html>
Hope this will help you...
Asp.Net Textbox Readonly using JavaScript
==>> In this post i want to make asp .net text box read only using java script .Some time we need this type of functionality in your website so you can easily implement in your website just copy paste blow code on your aspx page :----
1. ASPX PAGE CODE:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Asp.Net Textbox Readonly using JavaScript </title>
<script type="text/javascript">
function SettxtboxReadOnly() {
var txtName = document.getElementById("txtboxName");
txtName.readOnly = "readonly";
}
</script>
</head>
<body onload=" SettxtboxReadOnly()">
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtboxName" runat="server" Text="Read Only"></asp:TextBox>
</div>
</form>
</body>
</html>
1. ASPX PAGE CODE:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Asp.Net Textbox Readonly using JavaScript </title>
<script type="text/javascript">
function SettxtboxReadOnly() {
var txtName = document.getElementById("txtboxName");
txtName.readOnly = "readonly";
}
</script>
</head>
<body onload=" SettxtboxReadOnly()">
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtboxName" runat="server" Text="Read Only"></asp:TextBox>
</div>
</form>
</body>
</html>
Mouse or Cursor Position on the web page using JQuery in Asp .Net
==>> In this post i want to get current mouse or cursor position using JQuery :----
you just need paste this code on .aspx page you will find the your cursor position in browser....
1. ASPX PAGE CODE:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Mouse or Cursor Position on the web page using JQuery in Asp .Net</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
$(document).mousemove(function(e) {
$('#lblAxistxt').html("X Axis: "+e.pageX+"<br/>"+ "Y Axis: "+e.pageY);
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<label id="lblAxistxt" style="background-color:Aqua;" />
</div>
</form>
</body>
</html>
DEMO
Mouse or Cursor Position on the web page using JQuery in Asp .Net
you just need paste this code on .aspx page you will find the your cursor position in browser....
1. ASPX PAGE CODE:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Mouse or Cursor Position on the web page using JQuery in Asp .Net</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
$(document).mousemove(function(e) {
$('#lblAxistxt').html("X Axis: "+e.pageX+"<br/>"+ "Y Axis: "+e.pageY);
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<label id="lblAxistxt" style="background-color:Aqua;" />
</div>
</form>
</body>
</html>
DEMO
Wednesday, April 10, 2013
Calculating difference between two date in Years, Months and Days & Geting Age from DOB to current date in C# ASP .NET
==>> Some time we need calculate date in project i need get Year Month and Day from the date of birth to current date so i work on find this solution and now sharing with you .This is perfect solution for find difference between two date.
You need create asp .net website and add page that having name DateDiffe.aspx . You paste the below code according to page extension :-
1. ASPX PAGE CODE:-
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td>
Date 1</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Date 2</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="DateDiffBtn" runat="server" Text="Click"
onclick="DateDiffBtn_Click" />
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
</div>
</form>
2. ASPX.CS PAGE CODE:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class DateDiffe : System.Web.UI.Page
{
private int[] monthDay = new int[12] { 31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
private DateTime fromDate;
private DateTime toDate;
private int year;
private int month;
private int day;
protected void Page_Load(object sender, EventArgs e)
{
TextBox2.Text = DateTime.Now.Date.ToString();
}
protected void DateDiffBtn_Click(object sender, EventArgs e)
{
DateTime dtDOB = new DateTime();
dtDOB = Convert.ToDateTime(TextBox1.Text);
int Year1 = dtDOB.Year;
int Month1 = dtDOB.Month;
int Date1 = dtDOB.Day;
int Year2 = DateTime.Now.Year;
int Month2 = DateTime.Now.Month;
int Date2 = DateTime.Now.Day;
int Month = 0;
int Year = 0;
int Date = 0;
fromDate = Convert.ToDateTime(TextBox1.Text);
toDate = Convert.ToDateTime(TextBox2.Text);
//Day Calculation
int increment = 0;
if (this.fromDate.Day > this.toDate.Day)
{
increment = this.monthDay[this.fromDate.Month - 1];
}
if (increment == -1)
{
if (DateTime.IsLeapYear(this.fromDate.Year))
{
increment = 29;
}
else
{
increment = 28;
}
}
if (increment != 0)
{
day = (this.toDate.Day + increment) - this.fromDate.Day;
increment = 1;
}
else
{
day = this.toDate.Day - this.fromDate.Day;
}
//Month Calculation
if ((this.fromDate.Month + increment) > this.toDate.Month)
{
this.month = (this.toDate.Month + 12) - (this.fromDate.Month + increment);
increment = 1;
}
else
{
this.month = (this.toDate.Month) - (this.fromDate.Month + increment);
increment = 0;
}
//Year Calculation
this.year = this.toDate.Year - (this.fromDate.Year + increment);
Label1.Text = year + "Year" + month + "Month" + day + "Day";
}
}
Hope this will help you.........
Happy coding.............................
You need create asp .net website and add page that having name DateDiffe.aspx . You paste the below code according to page extension :-
1. ASPX PAGE CODE:-
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td>
Date 1</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Date 2</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="DateDiffBtn" runat="server" Text="Click"
onclick="DateDiffBtn_Click" />
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
</div>
</form>
2. ASPX.CS PAGE CODE:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
public partial class DateDiffe : System.Web.UI.Page
{
private int[] monthDay = new int[12] { 31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
private DateTime fromDate;
private DateTime toDate;
private int year;
private int month;
private int day;
protected void Page_Load(object sender, EventArgs e)
{
TextBox2.Text = DateTime.Now.Date.ToString();
}
protected void DateDiffBtn_Click(object sender, EventArgs e)
{
DateTime dtDOB = new DateTime();
dtDOB = Convert.ToDateTime(TextBox1.Text);
int Year1 = dtDOB.Year;
int Month1 = dtDOB.Month;
int Date1 = dtDOB.Day;
int Year2 = DateTime.Now.Year;
int Month2 = DateTime.Now.Month;
int Date2 = DateTime.Now.Day;
int Month = 0;
int Year = 0;
int Date = 0;
fromDate = Convert.ToDateTime(TextBox1.Text);
toDate = Convert.ToDateTime(TextBox2.Text);
//Day Calculation
int increment = 0;
if (this.fromDate.Day > this.toDate.Day)
{
increment = this.monthDay[this.fromDate.Month - 1];
}
if (increment == -1)
{
if (DateTime.IsLeapYear(this.fromDate.Year))
{
increment = 29;
}
else
{
increment = 28;
}
}
if (increment != 0)
{
day = (this.toDate.Day + increment) - this.fromDate.Day;
increment = 1;
}
else
{
day = this.toDate.Day - this.fromDate.Day;
}
//Month Calculation
if ((this.fromDate.Month + increment) > this.toDate.Month)
{
this.month = (this.toDate.Month + 12) - (this.fromDate.Month + increment);
increment = 1;
}
else
{
this.month = (this.toDate.Month) - (this.fromDate.Month + increment);
increment = 0;
}
//Year Calculation
this.year = this.toDate.Year - (this.fromDate.Year + increment);
Label1.Text = year + "Year" + month + "Month" + day + "Day";
}
}
Happy coding.............................
Subscribe to:
Posts (Atom)