Tuesday, May 8, 2007

Scrolling in DataGrid

in aspx page use "div" tag
ex:

*****div tag starting **********
id="scroll" style="height: 25em;overflow-y: auto; "> "

*******datagrid tag***********
****end of div tag*****

Monday, May 7, 2007

Handling Errors for asp.net application

To CREATE ERROR LOG FOR APPLICATION -:

1)create ErrorLog.txt in web application directory
2)create a cs file in project and copy this class


public class ErrorDesc
{
private string sLogFormat;
private string sErrorTime;
public ErrorDesc()
{
sLogFormat = DateTime.Now.ToShortDateString().ToString()+" "+DateTime.Now.ToLongTimeString().ToString()+" ==> ";
//this variable used to create log filename format "
//for example filename : ErrorLogYYYYMMDD
string sYear = DateTime.Now.Year.ToString();
string sMonth = DateTime.Now.Month.ToString();
string sDay = DateTime.Now.Day.ToString();
sErrorTime = sYear+sMonth+sDay;
}
public void ErrorLog(string sPathName, string sErrMsg)
{
StreamWriter sw = new StreamWriter(sPathName,true);
sw.WriteLine(sLogFormat + sErrMsg);
sw.Flush();
sw.Close();
}


now whenever in web page we want to handle try catch use :

try{
*******code****
}

catch(Exception ex)
{
ErrorDesc err=new ErrorDesc();
err.ErrorLog(Server.MapPath("ErrorLog.txt"),ex.Message+ ex.StackTrace);
}

Thursday, April 5, 2007

Allowing Only Numerics in TEXTBOX

In aspx page add following script->
function maskBox(e)
{
var keynum = null;
if(window.event){
keynum = e.keyCode;
}
else if(e.which){
keynum = e.which;
}
if(keynum){
if(keynum==8 || keynum==9){return true;}
else
{return isInt(String.fromCharCode(keynum));
}
}
}
function isInt(test)
{
var ints = "0123456789";
if(ints.indexOf(test)>-1)
{
return true;
}
return false;
}
then in page load just add the following line

textBox1.Attributes.Add("OnKeyDown","return maskBox(event);");

Code to Remove duplicate values from ArrayList

arr ->ArrayList with multiple values ,some unique and some repeating ex. {1,2,3,1,2,4,5}

for(i=0;i < arr.Count-1;i++)
{
for(j=i+1;j < arr.Count;j++)
{
if(arr[i].Equals(arr[j]))
{
arr.RemoveAt(j);
j = j - 1;
}
}
}

On executing code above arr={1,2,3,4,5}

Monday, January 29, 2007

script to list out all of the primary key to foreign key relationships

script for SQL Server 2000 that lists out all of the primary key to foreign key relationships by Micheal Imhoff.

http://michael.omnicypher.com/2007/01/foreign-key-information.html

select
pk_tbl.name as PRIMARY_KEY_TABLE
,pk_col.name as PRIMARY_KEY_COLUMN
,t_obj.name as FOREIGN_KEY_TABLE
,col.name as FOREIGN_KEY_COLUMN
,c_obj.name as CONSTRAINT_NAME
from
sysobjects c_obj
,sysobjects t_obj
,syscolumns col
,sysreferences ref
,sysobjects pk_tbl
,syscolumns pk_col
where
permissions(t_obj.id) != 0
and c_obj.xtype in ('F ')
and t_obj.id = c_obj.parent_obj
and t_obj.id = col.id
and col.colid in
(ref.fkey1,ref.fkey2,ref.fkey3,ref.fkey4,ref.fkey5,ref.fkey6,
ref.fkey7,ref.fkey8,ref.fkey9,ref.fkey10,ref.fkey11,ref.fkey12,
ref.fkey13,ref.fkey14,ref.fkey15,ref.fkey16)
and c_obj.id = ref.constid
and pk_tbl.id = ref.rkeyid
and pk_col.id = pk_tbl.id
and pk_col.colid = ref.rkey1
order by
pk_tbl.name, pk_col.name

Wednesday, December 27, 2006

Using Javascript in aspx page

To use javascript in aspx page for functions like window popup etc...
1)In aspx page html view write the necessary javascript:-

function OpenNew(message){ window.open("NewPage.aspx?" + message,"_blank"); }

2)In code behind write function to register page script ex.

protected void RegisterSubmitErrorScript(string Message) { string script = "< script language="'j a v a s c r i p t '">OpenNew('" + Message + "');"; Page.RegisterStartupScript("OpenNew",script);
}
3)Then anywhere in the page when u want to respond for new window to be open based on any condition being true or false call function above passing parameters if any ex.
RegisterSubmitErrorScript("param1=" + param);

Note:By changing javascript function "window.open" with any of other javascript functions,they can be performed.

Friday, December 15, 2006

ASP.NET DropDown -Selection

To change the selected index of a dropdown list already populated if Value or text is known

myDropDown.SelectedIndex = myDropDown.Items.IndexOf(myDropDown.items.findbytext(strCurrentState))

myDropDown.SelectedIndex = myDropDown.Items.IndexOf(myDropDown.items.findbyvalue(strCurrentState))