October 20, 2011

Add Third Party dll in GAC(Global Assembly Cache)

You can only add Strong named dll in GAC folder
Below are the steps to add dll in GAC
1.) Open Command Prompt of window (Go to start-->Run and Type 'cmd')
2.)you need Gacutil.exe which is mostly in the below path on the Drive.
     C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin
3.) In the command prompt go till here by command cd(Change Directory) ie
   
4.)Now use this command to register your dll in GAC
   gacutil /i mydll.dll

October 8, 2011

Java Script Code to compare two Date values in String


  function ValidateDate()
  {
 var fd=document.getElementById ('FromDate_txtDate');
 var td=document.getElementById ('ToDate_txtDate');

 if (Date.parse(fd.value) > Date.parse(td.value)) {

     alert("Invalid Date Range!\nFrom Date cannot be after To Date!")
    return false;
   }
  
}

Nested Class and Static Nested Class


//Static Nested Class
using System;
public class A
{
    int y;


    public static class B
    {
         static  int x;
       public static void F()
        {
            x = 10;
            Console.WriteLine("IN B  , X is"+x);
        }
    }
}
class Program
{
    public static void Main()
    {
        A.B.F();


    }
}

//Non Static Nested Class

using System;
public class A
{
    int y;


    public  class B
    {
        int x;
       public  void F()
        {
            x = 10;
            Console.WriteLine("IN B  , X is"+x);
        }
    }
}


class Program
{
    public static void Main()
    {
        A.B obj = new A.B();
        obj.F();
    }
}

October 4, 2011

ASP.NET Table Server Control



<asp:TableID="Table1"runat="server">
<asp:TableRowRunat="server"Font-Bold="True"
ForeColor="Black"BackColor="Silver">
<asp:TableHeaderCell>FirstName</asp:TableHeaderCell>
<asp:TableHeaderCell>LastName</asp:TableHeaderCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Bill</asp:TableCell>
<asp:TableCell>Evjen</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Devin</asp:TableCell>
<asp:TableCell>Rader</asp:TableCell>
</asp:TableRow>
</asp:Table>



Below code snippet is used to add a row dynamically in the Table Server Control


C#
protected void Page_Load(object sender,EventArgs e)
{
TableRowtr=new TableRow();
TableCell name=new TableCell();
name.Text="Test3";
tr.Cells.Add(name);
TableCell lname=new TableCell();
lname.Text="Test4";
tr.Cells.Add(lname);
Table1.Rows.Add(tr);
}

Multiple Button controls to work from a single Function


default.aspx
<asp:ButtonID="Button1"runat="server"Text="Button1"
OnCommand="Button_Command"CommandName="btn1"/>
<asp:ButtonID="Button2"runat="server"Text="Button2"
OnCommand="Button_Command"CommandName="btn2"/>





default.aspx.cs

protected voidButton_Command(Object sender,
System.Web.UI.WebControls.CommandEventArgs e)
{
switch(e.CommandName)
{
case("btn1"):
Response.Write("Button1 was clicked");
break;
case("btn2"):
Response.Write("Button2 was clicked");
break;
}
}

CodeExample for out modifier in C#


out modifier requires that a variable is assigned a value before 
returning from a method
using System;
class Test {
  static void Split(string name, out string firstNames, 
                    out string lastName) {
     int i = name.LastIndexOf(' ');
     firstNames = name.Substring(0, i);
     lastName = name.Substring(i+1);
  }
  static void Main( ) {
    string a, b;
    Split("Sachin Tendulkar", out a, out b);
    Console.WriteLine("FirstName:{0}, LastName:{1}", a, b);
  }
}

October 2, 2011

Code Snippet to Bind YearList


  public void GetYearList(DropDownList ddlYearList)
    {
        int i = DateTime.Now.Year;
        for (i = i - 1; i <= DateTime.Now.Year + 3; i++)
            ddlYearList.Items.Add(Convert.ToString(i));


      
    }

Code Snippet to Bind MonthList


 public void GetMonthList(DropDownList ddlMonthList)
    {
        DateTime month = Convert.ToDateTime("1/1/2000");
        for (int i = 0; i < 12; i++)
        {


            DateTime NextMonth = month.AddMonths(i);
            ListItem list = new ListItem();
            list.Text = NextMonth .ToString("MMMM");
            list.Value = NextMonth .Month.ToString();
            ddlMonthList.Items.Add(list);
        }
       




    }

Sql Convert Month Name to Number

Below is sql code to convert Month Name to Number ex.
January to 1


DATEPART(mm,CAST('MonthName'+ ' 1900' AS DATETIME))