Monday, April 30, 2012

how to make single radio button selection in gridview using javascript


[head id="Head1" runat="server">
[title>Grdview with Arraylist
[style type="text/css">
.Gridview
{
font-family:Verdana;
font-size:10pt;
font-weight:normal;
color:black;
width:300px;
}
[/style>
[script language="javascript" type="text/javascript">
function SelectSingleRadiobutton(rdbtnid) {
var rdBtn = document.getElementById(rdbtnid);
var rdBtnList = document.getElementsByTagName("input");
for (i = 0; i < rdBtnList.length; i++) {
if (rdBtnList[i].type == "radio" && rdBtnList[i].id != rdBtn.id)
{
rdBtnList[i].checked = false;
}
}
}
[/script>
[/head>
[body>
[form id="form1" runat="server">
[div>
[asp:GridView ID="gvdata" runat="server" CssClass="Gridview" AutoGenerateColumns="false" DataKeyNames="UserId" HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="White">
[Columns>
[asp:TemplateField>
[ItemTemplate>
[asp:RadioButton id="rdbUser" runat="server" OnClick="javascript:SelectSingleRadiobutton(this.id)" />
[/ItemTemplate>
[/asp:TemplateField>
[asp:BoundField DataField="UserName" HeaderText="Name"/>
[asp:BoundField DataField ="FirstName" HeaderText="FirstName" />
[asp:BoundField DataField="LastName" HeaderText="LastName" />
[asp:BoundField DataField="Location" HeaderText="Location" />
[/Columns>
[/asp:GridView>
[/div>
[/form>
[/body>
[/html>

how to calculate age of person and regular expression for mm/dd/yyyy format using JavaScript


[script type="text/javascript"]
function CalculateAge(birthday)
 {
var re=/^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d+$/;
if (birthday.value != '') {
            If (re.test(birthday.value)) Then
{
birthdayDate = new Date(birthday.value);
dateNow = new Date();
var years = dateNow.getFullYear() - birthdayDate.getFullYear();
var months=dateNow.getMonth()-birthdayDate.getMonth();
var days=dateNow.getDate()-birthdayDate.getDate();
if (isNaN(years)) {
document.getElementById('lblAge').innerHTML = '';
document.getElementById('lblError').innerHTML = 'Input date is incorrect!';
return false;
}
else {
document.getElementById('lblError').innerHTML = '';
document.getElementById('lblAge').innerHTML = years +' Years ' +months +' months '+days +' days';
}
}
else
{
document.getElementById('lblError').innerHTML = 'Date must be mm/dd/yyyy format';
return false;
}}}
[/script]

[/head>
[body>
[form id="form1" runat="server">
[div>
Date of Birth :(mm/dd/yyyy)
[span style="color: Red">
[asp:Label ID="lblError" runat="server">
[br />
Age : [span id="lblAge">

[/div>
[/form>
[/body>
[/html>

How to disable right click on asp.net web page using JavaScript | Disable mouse right click on webpage


[script language="JavaScript" type="text/javascript"]
//Message to display whenever right click on website
var message = "Sorry, Right Click have been disabled.";
function click(e) {
if (document.all) {
if (event.button == 2 || event.button == 3) {
alert(message);
return false;
}
}
else {
if (e.button == 2 || e.button == 3) {
e.preventDefault();
e.stopPropagation();
alert(message);
return false;
}
}
}
if (document.all) {
document.onmousedown = click;
}
else {
document.onclick = click;
}
[/script]
[/head]
[body]
[form id="form1" runat="server"]
[div]
[/div]
[/form]
[/body]
[/html]

Saturday, April 28, 2012

Watermark Extender


[asp:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" runat="server"
TargetControlID ="textw" WatermarkText ="Enter Name Please"]
                    [/asp:TextBoxWatermarkExtender]
     [asp:TextBox ID="textw" runat="server"][/asp:TextBox]

Monday, April 23, 2012

Difference between where and having clause


1. The WHERE clause specifies the criteria which individual records must meet to be selcted by a query. It can be used without the GROUP BY clause. The HAVING clause cannot be used without the GROUP BY clause.
2. The WHERE clause selects rows before grouping. The HAVING clause selects rows after grouping.
3. The WHERE clause cannot contain aggregate functions. The HAVING clause can contain aggregate functions.
 The HAVING clause allows you to filter the results of aggregate functions,
such as COUNT() or AVG() or SUM(), or MAX() or MIN(), just to name a few.
HAVING provides you a means to filter these results in the same query,
as opposed to saving the results of a WHERE clause SQL statement to a temporary table
and running another query on the temporary table results to extract the same results.