Code-snippets
public void ClearInputs(ControlCollection ctrls)
{
foreach (Control ctrl in ctrls)
{
if (ctrl is TextBox)
((TextBox)ctrl).Text = string.Empty;
ClearInputs(ctrl.Controls);
}
}
//To add theme in pre_init
Page.Theme = ConfigurationManager.AppSettings["ESPL_Theme"].ToString();
static void CountWordOccurrence()
{
//tell the user to enter their sentence
Console.WriteLine("\nPlease enter the sentence to be tested.");
//split their input into a string array
string[] words = Console.ReadLine().Split(' ');
//create our SortedList for holding our words and their count
SortedList wordList = new SortedList();
//variable to hold how many times a word appears in the string
int numWords = 0;
//now we loop through the string array
foreach (string word in words)
{
//check and see if this word is in our list yet
if (!(wordList.ContainsKey(word)))
{
//it isnt there so we add it with a value of 1
//since it's the words first occurrence
wordList.Add(word, 1);
//increment our word counter
numWords++;
}
else
{
//since the word dous exist we get the count of times it exists
int iWordCount = (int)wordList[word];
//we then increment the count for that word in the list
wordList[word] = iWordCount + 1;
}
}
//To call some function in masterpage event
HtmlGenericControl body = (HtmlGenericControl)Page.Master.FindControl("bodyMaster");
body.Attributes.Add("onload", "fnonload();");
//JS function for Check box-without post back
function fnCheckEntry()
{
if(document.getElementById("<%=checkBirthDate.ClientID %>").checked==true)
{
document.getElementById("<%=lblFrom.ClientID%>").style.visibility="visible";
document.getElementById("<%=txtDate1.ClientID%>").style.visibility="visible";
document.getElementById("<%=lblTo.ClientID%>").style.visibility="visible";
document.getElementById("<%=txtDate2.ClientID%>").style.visibility="visible";
var date=new Date();
var day=date.getDate();
var month=date.getMonth()+1;
var year=date.getFullYear();
document.getElementById("<%=txtDate1.ClientID%>").value=month+'/'+day+'/'+year;
document.getElementById("<%=txtDate2.ClientID%>").value=month+'/'+day+'/'+year;
}
else
{
document.getElementById("<%=lblFrom.ClientID%>").style.visibility="hidden";
document.getElementById("<%=txtDate1.ClientID%>").style.visibility="hidden";
document.getElementById("<%=lblTo.ClientID%>").style.visibility="hidden";
document.getElementById("<%=txtDate2.ClientID%>").style.visibility="hidden";
}
}
function fnonload()
{
document.getElementById("<%=lblFrom.ClientID%>").style.visibility="hidden";
document.getElementById("<%=txtDate1.ClientID%>").style.visibility="hidden";
document.getElementById("<%=lblTo.ClientID%>").style.visibility="hidden";
document.getElementById("<%=txtDate2.ClientID%>").style.visibility="hidden";
document.getElementById("<%=lblFrom1.ClientID%>").style.visibility="hidden";
document.getElementById("<%=txtFrom1.ClientID%>").style.visibility="hidden";
document.getElementById("<%=lblTo1.ClientID%>").style.visibility="hidden";
document.getElementById("<%=txtTo4.ClientID%>").style.visibility="hidden";
document.getElementById("<%=lblFrom3.ClientID%>").style.visibility="hidden";
document.getElementById("<%=txtFrom3.ClientID%>").style.visibility="hidden";
document.getElementById("<%=lblTo3.ClientID%>").style.visibility="hidden";
document.getElementById("<%=txtTo5.ClientID%>").style.visibility="hidden";
}
//Selecting currency value from dropdown with out postback
ClientScriptManager cs1 = Page.ClientScript;
string sql1 = "Select distinct CurrencyTable.Fld_Currency,CurrencyTable.Fld_Currency_Value From CurrencyTable inner join PeriodicalSubscriptions on CurrencyTable.Fld_currency_code = PeriodicalSubscriptions.Fld_currency_code order by CurrencyTable.Fld_Currency";
dac1 = new DBAccess();
DataTable dt1 = new DataTable();
DataTable dtt = dac1.ExecuteDatatable(sql1, "TEXT", dt1);
for (int i = 0; i < dtt.Rows.Count; i++)
{
cs1.RegisterArrayDeclaration("Ddl_Currencyy", dtt.Rows[i][1].ToString());
}
//JS for above one
function fnCurrency()
{
var drp=document.getElementById("<%=Ddl_Currency.ClientID%>");
var txtValue=document.getElementById("<%=Txt_Rate.ClientID%>");
txtValue.value=Ddl_Currencyy[drp.selectedIndex];
}
Ddl_Currency.Attributes.Add("onChange", "return fnCurrency()");
//generic function
Sub fnFillDropDownList(ByVal ddl As DropDownList, ByVal dt As DataTable, ByVal sTextFieldName As String, ByVal sValueFieldName As String, ByVal sKeyValue As String)
ddl.DataSource = dt
ddl.DataTextField = sTextFieldName
ddl.DataValueField = sValueFieldName
ddl.DataBind()
If sKeyValue <> "" Then
ddl.Items(ddl.Items.IndexOf(ddl.Items.FindByValue(sKeyValue))).Selected = True
End If
End Sub 'end
Dim AccessSub As New EdulibDataAccess
Sql = "Select * from Subject"
DsAccReg = AccessSub.GetData(Sql).Copy()
fnFillDropDownList(DlSub1, DsAccReg.Tables(0), "Fld_Subject", "Fld_Subject_Code", sub1code)
/// <summary>
/// Function used Maximize/Minimize Filter Section
/// </summary>
function fnMinimize()
{
var Imgtitle;
Imgtitle=document.getElementById("imgMinimize").title
if(Imgtitle=='Minimize')
{
document.getElementById("tblUI").style.display='none';
document.getElementById("imgMinimize").title='Maximize';
document.getElementById("imgMinimize").src='../images/filtermaximize.gif';
}
else
{
document.getElementById("tblUI").style.display='block';
document.getElementById("imgMinimize").title='Minimize';
document.getElementById("imgMinimize").src='../images/filterminimize.gif';
}
}
<table id="tblHeader" runat="server" border="0" cellpadding="0" cellspacing="0" class="style2">
<tr>
<th class="FILTERHEADER" style="height: 15px; color: White;">
Filter Recieve Periodicals
</th>
<th width="2%" class="FILTERHEADER" align="right" style="height: 15px">
<img onclick="javascript:fnMinimize();" id="imgMinimize" name="imgMinimize" title="Minimize"
src="../images/filterminimize.gif" alt="Minimize Filter Section" width="11px"
height="12px" style="cursor: Hand" />
</th>
</tr>
</table>
<table bgcolor="#97CBFF" id="tblUI" class="style2">
<tr>
/////////////////////////////////////////////////////////////////////////////////////////////////////////
<script language="javascript" type="text/javascript">
//document.load=function(){alert('loading')};
// document.body.onload = function() {alert("ok");}
// document.body.unload = function() {confirm("Closing");}
function DoBlur(fld) { fld.className='normalfld';HideNotes();}
function fnMsg()
{
alert('Test Msg');
}
function fnPopUp(address,city,status,e)
{
//alert("Address : " + address + " - City : "+ city +" - Status : "+status);
}
function fnPopUp(ISSN1,pubplace1, e)
{
//var index = lst.selectedIndex;
//var noteString=lst.options[index].value;
var posx = 0;
var posy = 0;
e = (window.event) ? window.event : e;
posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
var finalString = "<strong></strong><span id='Note' onclick=\"HideNotes()\" onmouseover=\"this.style.cursor='pointer';\" style=\"color: red;padding-left: 180px;\">X</span><br />";
finalString += "ISSN : " + ISSN1 +"<br>";
finalString += "Publishedplace : " + pubplace1 +"<br>";
// alert(finalString);
document.getElementById("divFrame").style.top=posy + "px";
document.getElementById("divFrame").style.left=(posx - 250) + "px";
document.getElementById("divNote").innerHTML = finalString;
document.getElementById("divNote").style.top=posy + "px";
document.getElementById("divNote").style.left=(posx - 250) + "px";
document.getElementById("divFrame").style.height=document.getElementById("divNote").offsetHeight+ "px";
var divLeft=document.getElementById("divNote").style.left;
if (divLeft.substring(0,1)=="-")
{
if (divLeft.substring(1,divLeft.length-2) <= 200 )
{
document.getElementById("divNote").style.left="250px";
document.getElementById("divFrame").style.left="250px";
}
}
document.getElementById("divNote").style.visibility="visible";
document.getElementById("divFrame").style.visibility="visible";
}
function HideNotes(){
document.getElementById("divFrame").style.visibility = "hidden";
document.getElementById("divNote").innerHTML = "";
document.getElementById("divNote").style.visibility = "hidden";
}
//F0F0A0
</script>
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//filldata(dt);
string ISSN1 = string.Empty, pubplace1 = string.Empty;
ISSN1 = dt.Rows[i][3].ToString();
pubplace1 = dt.Rows[i][4].ToString();
//string sAddress = string.Empty, sCity = string.Empty, sSatus = string.Empty;
//sAddress = e.Row.Cells[2].Text;
//sCity = e.Row.Cells[3].Text;
//sSatus = e.Row.Cells[4].Text;
HtmlAnchor lnk = (HtmlAnchor)e.Row.Cells[4].Controls[1];
lnk.Attributes.Add("onclick", "fnPopUp('" + ISSN1 + "','" + pubplace1 + "',event);");
i++;
}
}
///LinQ
static void Main()
{
liqu ll = new liqu();
ll.liq12();
Console.ReadKey();
}
public void liq1()
{
/*int[] num = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
var no = from n in num
where n > 5
select n;
foreach (var numeric in no)
{
Console.WriteLine(numeric);
}*/
int[] num = { 0, 1, 2, 3, 4, 5 };
string[] numString = { "Zero", "One", "Two", "Three", "Four", "Five" };
var no = from n in num
where n < 3
select numString[n];
foreach (var numeric in no)
{
Console.WriteLine(numeric);
}
/*List<Employee> emp = new List<Employee>();
Employee e = new Employee();
e.Name = "Ram";
e.Age = 25;
emp.Add(e);
Employee e1 = new Employee();
e1.Name = "Jhon";
e1.Age = 29;
emp.Add(e1);
Employee e2 = new Employee();
e2.Name = "Sunil";
e2.Age = 19;
emp.Add(e2);*/
/*var objEmp = from em in emp
where em.Age > 20
select em;
foreach (var emp1 in objEmp)
{
Console.WriteLine(emp1.Name + "--" + emp1.Age);
}*/
/* var objEmp = from em in emp
where em.Age > 20
select em.Name.ToUpper();
foreach (var emp1 in objEmp)
{
Console.WriteLine(emp1);
}*/
}
public void liq2()
{
List<Employee> emp = new List<Employee>();
Employee e = new Employee();
e.Name = "Ram";
e.Age = 25;
emp.Add(e);
Employee e1 = new Employee();
e1.Name = "Jhon";
e1.Age = 29;
emp.Add(e1);
Employee e2 = new Employee();
e2.Name = "Sunil";
e2.Age = 19;
emp.Add(e2);
var objEmp = from em in emp
where em.Age > 20
orderby em.Name, em.Age descending
select new { UserName=em.Name,UserAge=em.Age };
foreach (var emp1 in objEmp)
{
Console.WriteLine(emp1.UserName + "--" + emp1.UserAge);
}
}
public void liq4()
{
int[] numeric = { 1, 2, 3, 4, 5, 6, 7, 8 };
var no =from num in numeric
orderby num descending
select num;
var noo = no.Take(5);
var no1 = (noo.TakeWhile(n1 => n1 >6)).Take(1); //lamda expression....
foreach (var n in no1)
Console.WriteLine(n);
}
public void liq5()
{
int[] numeric = { 1, 2, 10, 4, 5, 6, 7, 8 };
var noo = from num in numeric
select num;
//var no1 = noo.Skip(5);
//Checking condition wont be applied once it fails while iterating the array.
var no1 = noo.SkipWhile(n1 => n1 < 6); //lamda expression....
foreach (var n in no1)
Console.WriteLine(n);
}
public void liq6()
{
int[] odd = { 1,3,5,7,9 };
int[] even = { 2,4,6,8,10 };
var noo = from od in odd
from evn in even
select new { od, evn };
//var no1 = noo.SkipWhile(n1 => n1 < 6); //lamda expression....
foreach (var n in noo)
Console.WriteLine(n.od +"--"+n.evn);
}
public void liq7()
{
int[] odd = { 1, 3, 5, 7, 9 };
int[] even = { 2, 4, 6, 8, 10 };
var noo = from od in odd
from evn in even
select new { od, evn };
var no1 = noo.Take(3);
//var no1 = noo.SkipWhile(n1 => n1 < 6); //lamda expression....
foreach (var n in no1)
Console.WriteLine(n.od + "--" + n.evn);
}
public void liq8()//Union
{
int[] odd = { 1, 3, 5, 7, 9 };
int[] even = { 2, 4, 6, 8, 10 };
/*var noo = from od in odd
from evn in even
select new { od, evn };*/
var no1 = odd.Union(even);
foreach (var n in no1)
Console.WriteLine(n);
}
public void liq9()//Intersect
{
int[] odd = { 1, 3, 5, 7, 9 };
int[] even = { 2, 3, 6, 8, 10 };
var no1 = odd.Intersect(even);
foreach (var n in no1)
Console.WriteLine(n);
}
public void liq10()//Sum
{
int[] odd = { 1, 3, 5, 7, 9 };
int[] even = { 2, 3, 6, 8, 10 };
var no1 = odd.Union(even);
var noo = no1.Sum();
Console.WriteLine(no1.Count());
Console.WriteLine(noo);
/*foreach (var n in noo)
Console.WriteLine(n);*/
}
public void liq11()//Sum
{
ArrayList str =new ArrayList();
str.Add(12.5);
str.Add("Ram");
str.Add(12);
str.Add("Sunil");
str.Add(18.50);
str.Add(null);
var noo = str.OfType<String>();
foreach (var n in noo)
Console.WriteLine(n);
}
//XML
class xpth
{
static void Main()
{
xpth objX = new xpth();
objX.xmlWrt2();
Console.ReadKey();
}
private void xmlRd()
{
XmlDocument doc = new XmlDocument();
doc.Load(@"D:\stu.xml");
//doc.LoadXml("<Student><Name>Sunil</Name><Name>Jhon</Name></Student>");
//XmlNodeList objNodList = doc.SelectNodes("/Student/Name[@Age<=25]");
XmlNodeList objNodList = doc.SelectNodes("/Student/Name[position()<=1]");
foreach (XmlNode nod in objNodList)
{
Console.WriteLine(nod["FirstName"].InnerText + "--" + nod["LastName"].InnerText + "--" + nod.Attributes["Age"].InnerText);
}
}
private void xmlWrt()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<Student><Name>Sunil</Name><Name>Jhon</Name></Student>");
doc.Save(@"D:\testxml1.xml");
}
private void xmlWrt2()
{
XmlTextWriter wrt = new XmlTextWriter(@"D:\testxml2.xml", null);
//wrt.Settings.Indent = true;
wrt.Formatting = Formatting.Indented;
wrt.WriteStartDocument();
wrt.WriteStartElement("Students");
wrt.WriteStartElement("Name");
wrt.WriteStartAttribute("Age");
wrt.WriteString("25");
wrt.WriteEndAttribute();
wrt.WriteStartElement("FirstName");
wrt.WriteString("Ram");
wrt.WriteEndElement();
wrt.WriteStartElement("LastName");
wrt.WriteString("Kumar");
wrt.WriteEndElement();
wrt.WriteEndElement();
wrt.WriteStartElement("Name");
wrt.WriteStartElement("FirstName");
wrt.WriteString("Jhon");
wrt.WriteEndElement();
wrt.WriteStartElement("LastName");
wrt.WriteString("David");
wrt.WriteEndElement();
wrt.WriteEndElement();
wrt.WriteEndElement();
wrt.WriteEndDocument();
wrt.Close();
}
}
//Collections
class collec
{
static void Main()
{
collec c = new collec();
c.fnStack();
c.fnQueue();
// c.fnAryList();
Console.ReadKey();
}
private void fnStack()
{
Stack objStk = new Stack();
objStk.Push("Jhon");
objStk.Push("Ram");
objStk.Push("Cegon");
objStk.Push("Sunil");
int n = objStk.Count;
n = n - 1;
for (int i = 0; i <= n; i++)
{
Console.WriteLine(objStk.Pop() + "---" + i.ToString());
}
}
private void fnQueue()
{
Queue objQue = new Queue();
objQue.Enqueue("Jhon");
objQue.Enqueue("Ram");
objQue.Enqueue("Cegon");
objQue.Enqueue("Sunil");
int n = objQue.Count;
n = n - 1;
for (int i = 0; i <= n; i++)
{
Console.WriteLine(objQue.Dequeue() + "---" + i.ToString());
}
}
private void fnAryList()
{
ArrayList objAry = new ArrayList();
objAry.Add("A");
objAry.Add("Bajana");
objAry.Add("C");
objAry.Add("D");
objAry.Insert(2, "T");
//objAry.RemoveAt(3);
//objAry.Sort();
//objAry.Reverse(1, 2);
if (objAry.Contains("D"))
{
Console.WriteLine("Exist");
}
int n = objAry.Count;
n = n - 1;
for (int i = 0; i <= n; i++)
{
Console.WriteLine(objAry[i].ToString() + "---" + i.ToString());
}
objAry.Clear();
}
}
//Delegates
#region "Class Delg"
class delg
{
#region "Global variable declaration"
delegate void delSample();
delegate void delSamplePar(int i);
#endregion
#region "Main function"
static void Main()
{
delg d = new delg();
delSample del = new delSample(d.fnName);
del += new delSample(d.fnAge);
del += new delSample(d.fnCity);
del -= new delSample(d.fnAge); //Multicast delegate...
//Ananomous Method...
//del += delegate()
//{
// Console.WriteLine("Ananomous Method");
//};
del();
//delSamplePar delp = new delSamplePar(d.fnAge);
//delp(55);
Console.ReadKey();
}
#endregion
private void fnName()
{
Console.WriteLine("Delegate function");
}
private void fnAge()
{
Console.WriteLine(25);
}
private void fnAge(int iAge)
{
Console.WriteLine(iAge);
}
private void fnCity()
{
Console.WriteLine("Blore");
}
}
#endregion
/////////////////////////////////////////////////////////////////////////////////////////////
<body onload="cls()">
function cls()
{
var txt= document.getElementById('<%=lblDate.ClientID %>');
txt.innerText=window.Date();
}
fnMsg();
function fnMsg()
{
//alert(window.Date());
//setTimeout("cls()",1000);
setInterval("cls()",1000);
}