Wednesday, November 25, 2009

Some Tricks 'n' Tips

ServicePeriodDescription (a column in table ServicePeriod )
---------------------------------- ---------------------------
January 2009
January 2008
January 2006 --- using the below query it updates the data like jan 09,jan 08,jan 06

update ServicePeriod set ServicePeriodDescription = left(ServicePeriodDescription,3) + ' ' + right(ServicePeriodDescription,2) where ServicePeriodDescription like '%jan%'

----------------------------------------------------------------------------------------------
Declare @qt as varchar(1000)
set @qt = ''''print @qtselect 'insert into program values ',ProgramID, ',', ProgramCode ,',', @qt+ Description + @qt from program
It creates the Insert Script for the table for columns included in the query.
----------------------------------------------------------------------------------------------
Check All check boxes either in grid or form using javascript coded in .cs file
String cbID;
String js;
int i = 0;
js = "";
for(i=2; i<(dataGrid.Items.Count+2); i++)
{
cbID = "dataGrid__" + "ctl" + i + "_chkSelect";
js += "if(document.getElementById('chkSelectAll').checked == true) {
document.getElementById('" + cbID + "').checked = false
}
else
{
document.getElementById('" + cbID + "').checked = true
};"
;}
chkSelectAll.Attributes.Add("onclick", js);

----------------------------------------------------------------------------------------------
Find whether a year is loop year or not
public static bool IsLeapYear (int year)
{
if (DateTime.IsLeapYear(year))
{
return true;
}
else
{
return false;
}}
-------------------------------------------------------------------------------------
Extract Numbers from a combineString c# Code

String str="January2007";

static string ExtractNumbers(string expr)
{
return string.Join(null, System.Text.RegularExpressions.Regex.Split(expr, "[^\\d]"));
}

static string ExtractText(string expr)
{
return string.Join(null, System.Text.RegularExpressions.Regex.Split(expr, "[^A-z]"));
}

-------------------------------------------------------------------------------------
Checking only CheckList instead of checking all CheckBoxes in a form

function chkall()
{
for (var n=0; n < document.forms[0].length; n++)
{
if (document.forms[0].elements[n].type=='checkbox'&& document.forms [0].elements[n].name.indexOf('chklstReasonCodes') > -1)
{
document.forms[0].elements[n].checked=true;
}
}
return false;
}

CheckAll

-------------------------------------------------------------------------------------
Getting values from .Net to JavaScript and placing values in DataGrid Controls

//Get the Controls of Grid Using UniqueID* Property

DropDownList ddl = (DropDownList)e.Row.FindControl("ddl");
string strcmbDOBYEARId = ddl.UniqueID;

TextBox txtResult = (TextBox)e.Row.FindControl("txtResult");
string strResult = txtResult.UniqueID;

ddl.Attributes.Add("onchange", "PulltoTextBox('" + strcmbDOBYEARId + "','" + strResult + "')");

function PulltoTextBox(ddlid,txtid)
{
var array = document.getElementById(ddlid);
var array1 = document.getElementsByName(txtid);
var sel="";
sel=array.options[array.selectedIndex].text;
array1[0].value=sel + "-" + array[0].value;
}

-------------------------------------------------------------------------------------

No comments: