Wednesday, March 26, 2008

Simple Sorting Using C# - Descending


public class Sort
{
public static void Main()
{
int[] iArr = { 9, 4, 2, 7, 6, 1, 0, 5, 3, 8 };
int i=0, j, temp;
for (i = 0; i < iArr.Length; i++)
{
for (j = i + 1; j < iArr.Length; j++)
{
if (iArr[i] < iArr[j]) // Descending
{
temp = iArr[i];
iArr[i] = iArr[j];
iArr[j] = temp;
}
} Console.WriteLine("iArr["+i+"] =>" + "{0}", iArr[i]);
}
Console.ReadLine();
}
}


Wednesday, March 19, 2008

Parser Error Message: Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

Solution

If Your Using Ajax Extension In Your Project Then you have to Add This following Dll To Your Project Bin folder System.Web.Extensions.Design.dllSystem.Web.Extensions.dll,because it may not be installed in the server where you are hosting your project,thats why you are getting the following Parser Error Message.

Line 63: </httpHandlers>
Line 64: <httpModules>
Line 65: <add name="ScriptModule" type="System.Web.Handlers.ScriptModule,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
Line 66: </httpModules>
Line 67:
Note:Add that Two Dll to your project, this two dll available in the following Path if you installed ajax extension in your system,
C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025


How To Set TextArea Max Length


<html>
<head>
<script type="text/javascript" language="javascript">
function chkLength(evt,len)
{
var str = document.getElementById(evt.id);
if(str.value.length < len)
{
return true;
}
else
{
return false;
}
}
</script>

</head>
<body>
<textarea id="txtArea" rows=5 cols=40 onkeypress="return chkLength(this,100);" ></textarea>
</body>


Program Demo
Note:IE Supported


Tuesday, March 18, 2008

Capture Mouse Click Event


<html>
<head>
<title>Capture Mouse Click Event</title>
<script language="javascript">
function noLeftClick()
{
switch (event.button)
{
case 1:
alert('You Clicked Left-Click ');
break;
case 2:
alert('You Clicked Right-Click.');
break;
}
}
document.onmousedown=noLeftClick
</script>
</head>
<body>
<h5>Click Any Were Within Browser</h3>
</body>
</html>
Program Demo

Note:IE Supported


Tuesday, March 11, 2008

Default values for bool, int, double, string, char, reference-type variables

TypeDefault Value


bool false


int 0


float 0


string null


char '\0'


ReferenceType null



Monday, March 10, 2008

How To Rename The Database In SQL Server

sp_renamedb
Changes the name of a database.

Syntax
sp_renamedb [ @dbname = ] 'old_name' , [ @newname = ] 'new_name'


[@dbname =] 'old_name'
              The current name of the database. old_name is sysname

[@newname =] 'new_name'
             The new name of the database. new_name must follow the rules for identifiers


Example:

CREATE DATABASE xample

sp_renamedb
'xample','Example'


How To Rename Column In Sql Server

Syntax:
sp_rename [ @objname = ] 'object_name' ,
                   [ @newname = ] 'new_name' ,
                   [ @objtype = ] 'object_type' ]
  
sp_rename
          Changes the name of a user-created object

'object_name'  
          Table ,View,column.

'new_name'
          New name which have to be replaced the old name.

[@objtype =] 'object_type'
         Specifying it's belong to which type like 
Column, Index etc.

Example:

use pubs

SP_RENAME
'DISCOUNTS.stor_id', 'STORID','COLUMN'

In this example Discounts is table name, stor_id is old_columnname, storid in new_columnname, column is an object type.



Thursday, March 6, 2008

Download Internet Explorer 8 Beta

Internet Explorer 8 takes the Web experience beyond the page and introduces a new way to seamlessly experience the power of the Web whether you are a Web developer writing to standards, or an end user discovering a new online service. This beta release is available to everyone, but is primarily for Web developers and designers to test the new tools, layout engine, and programming enhancements.

Courtesy:
Microsoft


How to select ROW in datagrid using Javascript


Program To Select Row In DataGrid Or Gridview Using JavaScript,Have To Use TemplateColumn,AutoGenerateColumns="false"
// JScript File JSdg.js
function rowBind()
{
var navRoot,node,dgRowid = null,tBody,rwVal;
var Prev = null,Curr = null;

if(document.all && document.getElementById)
{
navRoot = document.getElementById('dg');
// Can Be Used For Both DataGrid & GridView,
//Have To Give The Cleint ControlId.

if(navRoot != null)
{
tBody = navRoot.childNodes[0];

for(i=0;i<tBody.childNodes.length;i++)
{
node = tBody.childNodes[i];
if(node.tagName == "TR")
{
node.onmousedown = function()
{
dtRowid = this.rowIndex;
rVal = dtRowid+2;
if(dtRowid < 8)
{
rwVal = 'dg$ctl0'+ rVal+'$txtAuId';
}
else
{
rwVal = 'dg$ctl'+rVal+'$txtAuId';
}

var ctrl1 = document.getElementById(rwVal);
if(Prev != null)
{
node.parentElement.children[Prev].style.background = "#FFFFFF";
}
Curr = this.rowIndex;
if(Curr != null)
{
node.parentElement.children[Curr].style.background = "#D8E8FF";
Prev = Curr;
}
alert(ctrl1.value);
}
}
}
}
}
}

CodeBehind

SqlConnection Con = new SqlConnection(@"SERVER=YourSERVERNAME;DATABASE=PUBS;UID=sa;PWD=sa;");
SqlDataAdapter Da = new SqlDataAdapter();
DataSet Ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
Da = new SqlDataAdapter("Select * from Authors", Con);
Da.Fill(Ds);
dg.DataSource = Ds;
dg.DataBind();
}

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


<!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>Custom DataGrid</title>


<script type="text/javascript" language="javascript"
src="JavaScript/JSdg.js"></script>


</head>


<body onload="rowBind();">


<form id="form1" runat="server">

<div>

<asp:DataGrid ID="dg" runat="server" AutoGenerateColumns="false" ShowHeader="false">

<Columns>

<asp:TemplateColumn>

<ItemTemplate>
<asp:TextBox ID="txtAuId" ReadOnly="true" runat="server"
Text='<%# Bind("au_id") %>'
Style="background-color: Transparent; border: 0px;">
</asp:TextBox>
</ItemTemplate>

</asp:TemplateColumn>

<asp:TemplateColumn>

<ItemTemplate>

<asp:TextBox ID="txtAuName" ReadOnly="true" runat="server"
Text='<%# Bind("au_lname") %>'
Style="background-color: Transparent; border: 0px;">
</asp:TextBox>

</ItemTemplate>

</asp:TemplateColumn>

</Columns>

</asp:DataGrid>

</div>

</form>

</body>

</html>


Tuesday, March 4, 2008

Move Item Between ListBox


Program To Move Item Between ListBox (Select/Deselect All, Move Single Item, MultiSelect)


// JScript File(JSList.js)

var srclb,destlb;
var Flag ;
function moveAll(evt)
{

if(evt.id == 'btnSel' || evt.id == 'btnADitem')
{
srclb = document.getElementById('lboxSource');
destlb =document.getElementById('lboxdest');
}
else if(evt.id == 'btnDesel' || evt.id == 'btnRMitem')
{
srclb = document.getElementById('lboxdest');
destlb =document.getElementById('lboxSource');
}
if(srclb != null && destlb != null)
{
Flag = true;
while(Flag)
{
Flag = false;
for(var i=0;i<srclb.length;i++)
{
if(evt.id == 'btnADitem' || evt.id == 'btnRMitem')
{
if(srclb[i].selected)
{
exChange(i);
}
}
else if(evt.id == 'btnSel' || evt.id == 'btnDesel')
{
exChange(i);
}
}
}
}
}

function exChange(iVal)
{
destlb.appendChild(srclb[iVal].cloneNode(true));
srclb.removeChild(srclb[iVal]);
Flag = true;
}

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

<!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>ListBox</title>

<script type="text/javascript" language="javascript" src="JavaScript/JSList.js"></script>

</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<asp:ListBox ID="lboxSource" SelectionMode="Multiple"
runat="server" Height="122px" Width="45px">
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>D</asp:ListItem>
<asp:ListItem>E</asp:ListItem>
<asp:ListItem>F</asp:ListItem>
</asp:ListBox>
</td>
<td style="width: 31px">

<input id="btnDesel" title="DeselectAll" type="button"
style=" position:relative; left: 3px; width: 27px; top: 88px; height: 27px;"
onclick="moveAll(this);" value="««" />

<input id="btnRMitem" title="Remove Item" type="button"
style=" position:relative; left: 3px; width: 27px; top: 35px; height: 25px;"
onclick="moveAll(this);" value="«" />

<input id="btnADitem" title="Add Item" type="button"
style=" position:relative; left: 3px; width: 26px; top: -23px; height: 29px;"
onclick="moveAll(this);" value="»" />

<input id="btnSel" title="SelectAll" type="button"
style=" position:relative; left: 3px; width: 25px; top: -83px; height: 28px;"
onclick="moveAll(this);" value="»»" />

</td>
<td>
<asp:ListBox ID="lboxDest" SelectionMode="Multiple"
runat="server" Height="122px" Width="45px"></asp:ListBox>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>



Creative Commons License
Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.