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;
}

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

Sunday, November 22, 2009

Some Quotes i like

---In Iife we make some reIationshipsand some are made by god.
---prradhinchey పెదవులు కన్నా దానం chesey చేతులు మిన్న
---All's well that ends వెల్ (which means that problems do not matter so long as the outcome is good).

Wednesday, November 18, 2009

Master Page Related

//TO find Controls from the ContentPlaceHolder
ContentPlaceHolder mpContentPlaceHolder;
TextBox mpTextBox;
mpContentPlaceHolder =(ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
if(mpContentPlaceHolder != null)
{
mpTextBox =
(TextBox) mpContentPlaceHolder.FindControl("TextBox1");
if(mpTextBox != null)
{
mpTextBox.Text = "TextBox found!";
}
}

Sunday, November 15, 2009

grid view conditional formatting

http://www.simple-talk.com/content/article.aspx?article=438

//To disp discontinued items in red and the unitsinstoock items less than '0' as blue
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{ if (e.Row.RowType == DataControlRowType.DataRow)
{
//We're only interested in Rows that contain data
//get a reference to the data used to databound the row
DataRowView drv = (DataRowView)e.Row.DataItem;
if (Convert.ToInt32(drv["UnitsInStock"]) == 0)
{
//The current product has 0 items in stock
e.Row.Font.Bold = true; //Make the font bold
e.Row.ForeColor = System.Drawing.Color.Red;
//Set the text color red
if (Convert.ToInt32(drv["UnitsOnOrder"]) > 0)
{
//The current out of stock item has already been ordered
//Make it blue
e.Row.ForeColor = System.Drawing.Color.Blue;
}
}
if ((bool)drv["Discontinued"])
{
//Discontinued product
//Add the image
Image img = new Image();
img.AlternateText = "Discontinued Product";
img.ImageAlign = ImageAlign.AbsMiddle;
img.ImageUrl = "arrow_down.gif";
img.Width = Unit.Pixel(10);
img.Height = Unit.Pixel(11);
e.Row.Cells[0].Controls.Add(img);
//Add the text as a control
e.Row.Cells[0].Controls.Add(new LiteralControl(" " + e.Row.Cells[0].Text));
} }}
-----------------------------------------------------------------------------------
string previousCat = "";
int firstRow = -1;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//We're only interested in Rows that contain data
//get a reference to the data used to databound the row
DataRowView drv = ((DataRowView)e.Row.DataItem);
if (previousCat == drv["CategoryName"].ToString())
{
//If it's the same category as the previous one
//Increment the rowspan
if (GridView1.Rows[firstRow].Cells[0].RowSpan == 0)
GridView1.Rows[firstRow].Cells[0].RowSpan = 2;
else
GridView1.Rows[firstRow].Cells[0].RowSpan += 1;
//Remove the cell
e.Row.Cells.RemoveAt(0);
}
else //It's a new category
{
//Set the vertical alignment to top
e.Row.VerticalAlign = VerticalAlign.Top;
//Maintain the category in memory
previousCat = drv["CategoryName"].ToString();
firstRow = e.Row.RowIndex;
} }}
-------------------------------------------------------------------------------