Search This Blog

Sunday, March 15, 2015

Conditionally Styling a columns rows in GridView Control

In .aspx.cs file Write the following code:  
private static int count = 0;
    protected void Page_Load(object sender, EventArgs  e)
    {
        if(!IsPostBack)
        {
            SqlConnection cn = new SqlConnection("data source=your sql server name;initial catalog=your db name;integrated security=sspi");
            string qry = "select * from employees";
            SqlCommand cmd = new SqlCommand(qry, cn);
            cn.Open();
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            DataSet ds = new DataSet();
            da.Fill(ds);
            cn.Close();
            Session["ds"] = ds;
            gvEmps.DataSource = ds;
            DataTable dt = ds.Tables[0];
            DataColumn dc = new DataColumn("Eligibility",typeof(string));
            dt.Columns.Add(dc);
            gvEmps.DataBind();
        }
    }
    protected void gvEmps_RowDataBound(object sender, GridViewRowEventArgs e)
    {
     
        if (count > 0)
        {
            GridViewRow gvr = e.Row;
            TableCell tc = gvr.Cells[3];

            string data = tc.Text;
            if (data != " "&&data!="doj")
            {
                DateTime dt = Convert.ToDateTime(data);
                int yrsDiff = DateTime.Now.Year - dt.Year;
                if (yrsDiff >= 5)
                {
                    TableCell tc1 = gvr.Cells[4];
                    tc1.Text = "Eligible";
                    tc1.Style.Add("color", "red");
                }
            }
        }
        if (count == 0)
        {
            count = 1;
        }
    }
Table Structure:

eidfnameagedojEligibility
1rijin2304-Oct-09 12:00:00 AMEligible
2kishore2304-Oct-14 12:00:00 AM

Sunday, August 3, 2014

Gridview with Hyperlink sample code

In .aspx file:

<asp:GridView ID="gvProducts" runat="server" AutoGenerateColumns="false">
    <AlternatingRowStyle BackColor="green" />
    <Columns>
      <asp:HyperLinkField HeaderText="Name" DataTextField="PName"
         DataNavigateUrlFields="pname"
       DataNavigateUrlFormatString="Sales.aspx?pname={0}" />
      <asp:BoundField HeaderText="MinQty" DataField="MinOrdQty" />
      <asp:BoundField HeaderText="MaxQty" DataField="MaxOrdQty" />
      <asp:BoundField HeaderText="UnitPrice" DataField="UnitPrice" />
    </Columns>
    </asp:GridView>

In .aspx.cs file:

protected void Page_Load(object sender, EventArgs e)
    {
        string strcn = "Data source=name-of-sql-server;initial catalog=database-name;integrated security=sspi";
        SqlConnection cn = new SqlConnection(strcn);
        SqlCommand cmd = new SqlCommand("select pname,minordqty,MaxOrdQty,UnitPrice from dbo.products", cn);
        try
        {
            cn.Open();
            DataSet ds = new DataSet();
            SqlDataAdapter DA = new SqlDataAdapter(cmd);
            DA.Fill(ds);
            DataTable dt = ds.Tables[0];
            //Session["ds"] = ds;
            gvProducts.DataSource = dt;
            gvProducts.DataBind();

        }
        catch (SqlException ex)
        {

        }
        finally
        {
            cn.Close();
        }
    }
In Details page (Sales.aspx) :
<asp:GridView ID="gvSales" runat="server"></asp:GridView>

In Sales.aspx.cs:

protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["pname"] != null)
        {
            string productName = Request.QueryString["pname"].ToString();
            if (productName != null && productName != string.Empty)
                DisplaySalesDetails(productName);
        }
    }
    private void DisplaySalesDetails(string pname)
    {
        string strcn = "Data source=ADMIN-PC\\SQLEXPRESS;initial catalog=adomaterial;integrated security=sspi";
        SqlConnection cn = new SqlConnection(strcn);
        string qry=@"select * from dbo.sales where pid in(select pid from products
        where pname='";
        qry+=pname+"');";
        SqlCommand cmd = new SqlCommand(qry,cn);
        try
        {
            cn.Open();
            DataSet ds = new DataSet();
            SqlDataAdapter DA = new SqlDataAdapter(cmd);
            DA.Fill(ds);
            Session["ds"] = ds;
            gvSales.DataSource = ds;
            gvSales.DataBind();

        }
        catch (SqlException ex)
        {

        }
        finally
        {
            cn.Close();
        }
    }
Table structure:
Products table:
PidPNameMidMinOrdQtyMaxOrdQtyActiveUnitPrice
1colgate15050065
2DoveSoap1100100025
3DoveShampoo150500150
4ParachuteOil2205080
5RinSoap25050015
6SurfExcel15050055
7VIM21010015
8EXO31015035
9Medimix32515025
10Pears41020026
11NoteBook45127048
12Cinthol2030023
13fiama42020067
Sales table:
SidQtyOriginalPriceTotalPriceDiscountActiveSaleDatePid
1101350120015023-Dec-11 12:00:00 AM3
2252000180020021-Aug-11 12:00:00 AM4
3201300100030013-Jun-10 12:00:00 AM1
41505500490060023-Dec-09 12:00:00 AM6
5501300110020002-Jun-08 12:00:00 AM10
6153753502501-Feb-12 12:00:00 AM2
7253375310027502-Feb-11 12:00:00 AM3
82003000250050007-Oct-10 12:00:00 AM5
91503300320010029-Jul-11 12:00:00 AM9
101003500320030015-Nov-10 12:00:00 AM8
11105505005002-Feb-11 12:00:00 AM6
12501100100010011-Aug-09 12:00:00 AM9
1380120095025023-Dec-10 12:00:00 AM7
14100250090040020-Oct-11 12:00:00 AM9
151201600150010003-Oct-12 12:00:00 AM7

Tuesday, July 22, 2014

Paging in GridView

In .aspx file :

<asp:GridView ID="GridView1" runat="server" PageSize="5" AllowPaging="true"         onpageindexchanging="GridView1_PageIndexChanging">
<PagerSettings Mode="Numeric" />
</asp:GridView>

In .aspx.cs file :

public partial class ADO_DATACONTROLS_Paging : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //sspi=Security Support Provider Interface ~= trusted connection
        if(!IsPostBack)
            DisplayEmployees();
    }

    private void DisplayEmployees()
    {
        string strcn = "data source=ADMIN-PC\\SQLEXPRESS;initial catalog=db17;integrated security=sspi";
        SqlConnection cn = new SqlConnection(strcn);
        SqlCommand cmd = new SqlCommand("select * from employees", cn);
        try
        {
            cn.Open();
            DataSet ds = new DataSet();
            SqlDataAdapter DA = new SqlDataAdapter(cmd);
            DA.Fill(ds);
            Session["ds"] = ds;
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        catch (SqlException ex)
        {

        }
        finally
        {
            cn.Close();
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        DataSet ds = (DataSet)Session["ds"];
        DataTable dt = ds.Tables[0];
        GridView1.DataSource = dt;
        GridView1.PageIndex = e.NewPageIndex;//this code must be written between Datasource and DataBind
        GridView1.DataBind();
    }
}

Table structure:

eidfnamelnameagesalarydeptdoj
1rajeevsukla2312000.net23-Oct-11 12:00:00 AM
2sowmyakumari2319000db13-Nov-10 12:00:00 AM
3kishorekumar2736000android16-Oct-11 12:00:00 AM
4abimanyubiswal22nullandroid20-Feb-10 12:00:00 AM
5sonikumar2421800.net21-Jun-09 12:00:00 AM
6anu_singh2212000db23-Oct-10 12:00:00 AM
7_dineshmoh%anty2315000.net26-Aug-09 12:00:00 AM
8nishala_kumari2218000db19-Jul-08 12:00:00 AM
1rajeevsukla2312000.net23-Oct-11 12:00:00 AM

Sorting in Gridview Control

Write the following code In .aspx page :


<asp:GridView ID="gvstudents" runat="server" AllowSorting="true" 

    OnSorting="gvstudents_sorting">

    </asp:GridView>

Code in .aspx.cs:


public partial class SortingEx : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            string strcon = "data source=name of sql server ;initial catalog=database name;integrated security=sspi or user id=sqlserver userid ; password=somepassword";
            string sConnection = strcon;
            DataSet ds = new DataSet();
            SqlConnection cn = new SqlConnection(sConnection);
            using (cn)
            {
                SqlCommand cmd = new SqlCommand("select * from employees", cn);
                using (cmd)
                {
                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = cmd;
                    da.Fill(ds);
                    gvstudents.DataSource = ds;
                    gvstudents.DataBind();
                    Session["ds"] = ds;
                    ViewState["sortcolumn"] = string.Empty;
                    ViewState["sortdirection"] = string.Empty;
                }
            }
        }
    }
    protected void gvstudents_sorting(object sender, GridViewSortEventArgs e)
    {
        if (Session["ds"] != null)
        {
           DataSet ds = (DataSet)Session["ds"];
           DataTable dt = ds.Tables[0];
           DataView dv = dt.DefaultView;//DataView ado.net view in t-sql 
            if (ViewState["sortcolumn"].ToString() == e.SortExpression.ToString())
            {
                if ("asc" == ViewState["sortdirection"].ToString())
                {
                    ViewState["sortdirection"] = "DESC";
                }
                else
                {
                    ViewState["sortdirection"] = "asc";
                }
            }
            else
            {
                ViewState["sortcolumn"] = e.SortExpression.ToString();
                ViewState["sortdirection"] = "asc";
            }
            if (dv != null)
            {
                dv.Sort = e.SortExpression + " " + ViewState["sortdirection"].ToString();
                //dv.Sort= "ename asc";
                gvstudents.DataSource = dv;
                gvstudents.DataBind();
            }
        }

    }
}

Table structure :

eidfnamelnameagesalarydeptdoj
1rajeevsukla2312000.net23-Oct-11 12:00:00 AM
2sowmyakumari2319000db13-Nov-10 12:00:00 AM
3kishorekumar2736000android16-Oct-11 12:00:00 AM
4abimanyubiswal22nullandroid20-Feb-10 12:00:00 AM
5sonikumar2421800.net21-Jun-09 12:00:00 AM
6anu_singh2212000db23-Oct-10 12:00:00 AM
7_dineshmoh%anty2315000.net26-Aug-09 12:00:00 AM
8nishala_kumari2218000db19-Jul-08 12:00:00 AM
1rajeevsukla2312000.net23-Oct-11 12:00:00 AM

Monday, July 21, 2014

Asp.net Gridview edit update and delete code

In GridViewEditUpdateDelete.aspx add the following code ( in the form tag )


<asp:GridView ID="gvPatients" AutoGenerateColumns="false" runat="server"
    AutoGenerateEditButton="true" AutoGenerateDeleteButton="true"
    DataKeyNames="PatientID"
        onrowediting="gvPatients_RowEditing"
        OnRowCancelingEdit="gvPatients_RowCancel" OnRowUpdating="gvPatients_RowUpdating"
        OnRowDeleting="gvPatients_RowDeleting"
        onselectedindexchanged="gvPatients_SelectedIndexChanged">
    <HeaderStyle BackColor="AliceBlue" ForeColor="Red"/>
    <Columns>
    <asp:TemplateField HeaderText="PatientID">
    <ItemTemplate>
    <asp:Label ID="lblPatientID" runat="server" Text='<%#Eval("PatientID") %>'/>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="PatientName">
    <EditItemTemplate>
    <asp:TextBox ID="tbName" runat="server" Text='<%#Eval("PatientName")%>' />
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="lblName" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"PatientName")%>' />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="AGE">
    <EditItemTemplate>
    <asp:TextBox ID="tbAge" runat="server" Text='<%#Eval("age")%>' />
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="lblAge" runat="server" Text='<%#Eval("age")%>' />
    </ItemTemplate>
    </asp:TemplateField>  
    </Columns>
    </asp:GridView>


In .aspx.cs page add the following code:


public partial class DataGridColumns : System.Web.UI.Page
{
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FillPatientInfo();
        }
    }
    private void FillPatientInfo()
    {
        //bad approach for getting connection string.
        string strcon = "data source=your sql server name ;initial catalog=your database name ;integrated security=sspi";
        SqlConnection cn = new SqlConnection(strcon);
        SqlCommand cmd = new SqlCommand("select * from patient", cn);
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        da.Fill(ds);
        gvPatients.DataSource = ds;
        gvPatients.DataBind();
        Session["dsPatients"] = ds;
        //GridView1.DataSource = ds;
        //GridView1.DataBind();
    }
    protected void gvPatients_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gvPatients.EditIndex = e.NewEditIndex;
        gvPatients.DataSource = (DataSet)Session["dsPatients"];
        gvPatients.DataBind();
    }
    protected void gvPatients_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblPatientID = (Label)gvPatients.Rows[e.RowIndex].FindControl("lblPatientID");
        SqlConnection cn = new SqlConnection("data source=ADMIN-PC\\SQLEXPRESS;initial catalog=palletechnologies;integrated security=sspi");
        SqlCommand cmd = new SqlCommand();
        StringBuilder sb = new StringBuilder();
        sb.Append("delete patient where patientid='" + lblPatientID.Text + "'");
        cmd.CommandText = sb.ToString();
        cmd.Connection = cn;
        cn.Open();
        cmd.ExecuteNonQuery();
        cn.Close();
        FillPatientInfo();
    }
    protected void gvPatients_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Label lblPatientID = (Label)gvPatients.Rows[e.RowIndex].FindControl("lblPatientID");
        TextBox tbAge = (TextBox)gvPatients.Rows[e.RowIndex].FindControl("tbAge");
        TextBox tbName = (TextBox)gvPatients.Rows[e.RowIndex].FindControl("tbName");
        SqlConnection cn = new SqlConnection("data source=ADMIN-PC\\SQLEXPRESS;initial catalog=palletechnologies;integrated security=sspi");
        SqlCommand cmd = new SqlCommand();
        StringBuilder sb = new StringBuilder();
        sb.Append("update patient set patientname='" + tbName .Text+ "',");
        sb.Append("age='"+tbAge.Text+"' where patientid='"+lblPatientID.Text+"'");
        cmd.CommandText = sb.ToString();
        cmd.Connection = cn;
        cn.Open();
        cmd.ExecuteNonQuery();
        cn.Close();
        gvPatients.EditIndex = -1;
        FillPatientInfo();
    }
    protected void gvPatients_SelectedIndexChanged(object sender, EventArgs e)
    {
        
    }
    protected void gvPatients_RowCancel(object sender, GridViewCancelEditEventArgs e)
    {
        gvPatients.EditIndex = -1;
        e.Cancel = true;
        gvPatients.DataSource = (DataSet)Session["dsPatients"];
        gvPatients.DataBind();
    }
}

Patient table structure: 

Create a patient table with PatientID,PatientName and Age columns.

Thursday, April 10, 2014

How to set startup url in asp.net mvc

1.Go to MVC web application property page and set Start Action Specific Page value equal to ControllerName/ActionMethodName ( refer below given screen shot )

Friday, December 20, 2013

What is an action method in MVC

An action method in mvc is a method which can able to redirect user to a view ( an action method can optionally pass model data to a view for rendering views ui filled with model data ).
OR
An action method is a method which is returning ActionResult .

Note: I For testing your knowledge in .net , c , cpp , aptitude , java and arithmetic you can visit the links present http://www.skillgun.com

Important links in skillgun .

arithmetic questions and answers
android interview questions and answers
c interview questions and answers
c++ interview questions and answers
java interview questions and answers
c# interview questions and answers

Tuesday, November 8, 2011

About Global.asax in ASP.NET


  • Global.asax is a file in asp.net
  • Global.asax file contains all the application level methods.like
  •       1.Application_Start 2.Application_End 3.Session_Start 4.Session_End etc..
  • Note: When you compile your code for the first time your ASP.NET runtime creates a class corresponding to Global.asax file with the Class name global_asax. This class inherits from HTTP Application class.
  • You can see the automatically created class in the C:\Documents and Settings\User\My Documents\Visual Studio 2008\WebSites\ApplicationName\global.asax file.

Friday, October 28, 2011

Adding new Nodes to XML File in C#

1.Create a Dummy xml file with the name Patients.xml in your solution explorer.
    Ex:
 <Patients>
  <Patient type="IP">
    <VistorNum>134</VistorNum>
    <FName>Maha</FName>
    <LName>Veer</LName>
    <Age>89</Age>
    <Sex>Male</Sex>
  </Patient>
</Patients>
 
2.Create the UI to accept data from users.(Write the below code in .aspx page)
   VisitorNum:<asp:TextBox ID="tbVstrNum" runat="server" ></asp:TextBox><br />
    FName:<asp:TextBox ID="tbFName" runat="server" ></asp:TextBox><br />
    LName:<asp:TextBox ID="tbLName" runat="server" ></asp:TextBox><br />
    Age:<asp:TextBox ID="tbAge" runat="server" ></asp:TextBox><br />
    Sex:<asp:TextBox ID="tbSex" runat="server" ></asp:TextBox><br />
    <asp:Button ID="btnInsertPat" Text="AddPatient" runat="server" 
            onclick="btnInsertPat_Click" />
3.Write the below code in code behind's button click method.
    protected void btnInsertPat_Click(object sender, EventArgs e)
    {
        XmlDocument doc = new XmlDocument();
        doc.Load(Server.MapPath("Patients.xml"));
        //Create a New patient node.
        XmlNode nPatient=doc.CreateNode(XmlNodeType.Element,"Patient",null);
        //Create visitornUm,FName,LName,Age,Sex nodes and add 
        //it to Patient Node
        XmlElement eVistNum= doc.CreateElement("VistorNum");
        eVistNum.InnerText = tbVstrNum.Text;
        XmlElement eFName = doc.CreateElement("FName");
        eFName.InnerText = tbFName.Text;
        XmlElement eLName = doc.CreateElement("LName");
        eLName.InnerText = tbLName.Text;
        XmlElement eAge = doc.CreateElement("Age");
        eAge.InnerText = tbAge.Text;
        XmlElement eSex = doc.CreateElement("Sex");
        eSex.InnerText = tbSex.Text;
        nPatient.AppendChild(eVistNum);
        nPatient.AppendChild(eFName);
        nPatient.AppendChild(eLName);
        nPatient.AppendChild(eAge);
        nPatient.AppendChild(eSex);
        //Get the Root Patients Node ref.
        XmlNode root=doc.SelectSingleNode("Patients");
        //Add New patient node to root patient node.
        root.AppendChild(nPatient);
        string sPath = Server.MapPath("Patients.xml");
        doc.Save(sPath);
        //elem.AppendChild(
    }
Sign Up for dot net training course 

Friday, September 9, 2011

Opening My Computer Using ASP.NET

Please use the HTML Input File Control for opening all the available Drives. Just Drag and drop the control
on to the .aspx page and check the result by clicking on the Browse Button.

India's #1 .NET Training

Sunday, August 28, 2011

How to Encrypt Connection String

For security reasons we need to encrypt the connection strings.
Encrypting and decrypting the connection string is very easy. Follow the Below steps to encrypt the Connection strings.
Encrypt Connection Strings:
  • Open visual studio command prompt.
  • type the given command  aspnet_regiis -pef  "connectionStrings"  "YourApplicationFullPath where your web.config file is present"  and then press Enter.


Decrypting Connection String:
  • aspnet_regiis -pdf  "connectionStrings" "YourApplicationFullPath where your web.config file is present"  and then press Enter.


Note : You need to use pef or pdf only if your website is created as a file system. If Your website is created as a IIS website then use pe or pd for encrypting or decrypting.

Thursday, August 18, 2011

is and as operators in C#

is Operator:
  • is operator Checks if an object is compatible with a given type 
  • An is expression evaluates to true if the provided expression is non-null, and the provided object     can  be cast to the provided type without causing  an exception to be thrown.
as Operator:
  • The as operator is used to perform conversions between compatible reference types      
  • The as operator is like a cast operation. However, if the conversion is not possible, as returns null instead of raising an exception
Ex:

public class Exam
{
    public string GetSubjectName()
    {
        return "C#";
    }
}
public class UnitTest
{
    public int GetTestNumber()
    {
        return 1;
    }
}

public partial class CSHARPSAMPLES_Keywords : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Exam e1 = new Exam();
    }
    public void Test(object o)
    {
        if (o is UnitTest)
        {
            UnitTest u = o as UnitTest;
            u.GetTestNumber();
        }
        else if (o is Exam)
        {
            Exam e = o as Exam;
            e.GetSubjectName();
        }
    }
}

Ternary Operators in C#

Ternary operators can be use full when we have only one simple if else condition.
Ternary Operator Syntax:

condition ? first_expression : second_expression;
Ex:
public class TernaryEx
{
    public int GetBigNum(int a, int b)
    {
        return a > b ? a : b;
        //in the above syntax if a is greater than b
        //the above expression returns a else it returns b.
    }
}
Note: SignUp for JobGuaranteed Training

Sunday, July 17, 2011

How to show XML Data in the Grid View

  • Create a Page with the Name XMLSample.aspx
  • Write the Below controls in the .aspx source Page.
  • Create an xml file on the desktop with Name Students ( See example xml at the End)
<asp:GridView ID="gvList" runat="server">
        </asp:GridView>
        Path:
        <asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnAdd" runat="server" Text="Add" onclick="btnAdd_Click" />
  • Write the Below code in the Code behind file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;


public partial class XMLSample : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        HttpPostedFile hpf=FileUpload1.PostedFile;
        string fName=FileUpload1.PostedFile.FileName;
        System.Data.DataSet ds = new System.Data.DataSet();
        ds.ReadXml(fName);
        gvList.DataSource = ds.Tables[0];
        gvList.DataBind();
        
        
    }
}

Note : Example Xml file.


<Students>
  <Student>
    <id>1312</id>
    <name>123</name>
    <age>123123</age>
  </Student>
  <Student>
    <id>6</id>
    <name>Ashoke</name>
    <age>23</age>
  </Student>
</Students>

Friday, July 15, 2011

Encrpt and Decrypt Connection String

For Security reasons we need to encrypt the connection strings.

How to Encrypt a connection string:
  • Open visual studio command prompt.
  • Change your command prompt location and should point to your application physical drive
  • Assume your application Name is DataSet and  is present in c:\Documents and Settings\Administrator\My Documents
  • type the below statements and then press enter to encrypt the connection
  • aspnet_regiis -pe "connectionStrings" -app "/DataSet"
How to Decrypt Connection:
  • Type the below command and press enter
  • aspnet_regiis -pd "connectionStrings" -app "/DataSet"
Note : See the below attached screen shot.

Saturday, July 9, 2011

Sealed class

Sealed class

  1. It is complete class
  2. It is allow creating an object
  3. It is also called instance class
  4. Inheritance is not possible for Sealed Class. Means No one can be able to inherit from a Sealed Class but sealed class can inherit from any other class (The Parent Class should not be Sealed Class).
  5. Sealed class can never acts as a Parent Class
  6. Static class is by default sealed class only.

Example for Sealed Class:

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

­­­­public sealed class ToyCalc

{

}

public class AdvancedToyCalc : ToyCalc

{

}

Note 1: The above Code is wrong since a sealed class can never act as a Base or Parent Class.

Note 2: But ToyCalc class can inherit from other classes ex.

Ex: ­­­­public sealed class ToyCalc: Toy

The Toy Class should not be a Static Class or SealedClass.

Abstract Class

Abstract Class:
  • When a class is not providing full functionality it recommended to declare that class as an Abstract class.
  • Method with out body is called an abstract method.
  • Ex: public abstract void GetArea ();
  • When class contain at least one abstract method then that class must be declared as abstract class.
  • All the abstract method must be overridden in the derived class.
  • We cant create object for Abstract class.
Ex :

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class AbstractClassSammple : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

Circle c = new Circle ();

c.print();

Response.Write(c.findarea()+" ");

Response.Write("
"
+c.print());

}

}

public abstract class Shape

{

private int x = 10;

private int y = 20;

public int print()

{

return (x + y);

}

public abstract double findarea();

}

public class Circle : Shape

{

private int r = 10;

public override double findarea()

{

double a = 3.14 * r * r;

return (a);

}

}

Wednesday, June 8, 2011

Important JavaScript Methods

The  below JavaScript methods are very much useful while writing JavaScript Code.
Note: Below Questions are Frequently asked in .NET Interviews
1.document.getElementById("ControlID");
2.document.getElementByName("Control Name");

Dom Properties:

the below properties are the freequently used properties while writing JavaScript Code.


z.innerHTML - the text value of z
z.nodeName - the name of z
z.nodeValue - the value of z
z.parentNode - the parent node of z
z.childNodes - the child nodes of z
z.attributes - the attributes nodes of z


Note: z Represents HTMLElement ( ex. Text Box or Radio Button )



Wednesday, May 18, 2011

Why .NET is better than Java

There are couple things we need to understand before comparing Java and .NET.

1.Usually softwares are developed to automate any business and to reduce human intervention.
2.Let us Say Palle Technologies wanted to develop a software for XYZ hospital. Since XYZ hospital wanted to automate the Registration,Admission,Scheduling etc process and they decided to develop a software which makes their daily work faster and increases Revenue.
3.They gave contract of developing an application to PalleTechnologiies and asked to come with feasible choice of softwares and they gave us 6 months time for development for what ever the technology they choose.
4.We analysed the requirement and estimated development and maintainence effort for Both Java and .NET
5. We saw significant notable differences between JAVA and .NET
Note: Assumed Application Life time = 15 years.
 Look at the Estimated Costs Required for creating the application for XYZ company.
Estimation for Java Application :
  Java Total Resources Required for Development (6 months)= 6 resources
  Cost of Each Resource= 6* 20000 INR/Month
 Total Resources Cost During Development=720000 INR
Note: We assumed XYZ company is going to use this software for 15 years
Cost of Maintaining the Application for 1 year =3*20000 INR/Person/Month*12 Months=720000
Cost of Maintaining the Application for 15 years=10800000 INR.
Cost of Softwares and Servers = 60000 INR.
Total Cost=11580000 INR.
Estimation for .NET Application :

 .NET Total Resources Required for Development (6 months)= 5 resources 
  Cost of Each Resource= 5* 20000 INR/Month
 Total Resources Cost During Development=700000 INR
Note: We assumed XYZ company is going to use this software for 15 years
Cost of Maintaining the Application for 1 year with 2 Resources=2*20000 INR/Person/Month*12 Months=480000
Cost of Maintaining the Application for 15 years=7200000 INR. 
Cost of Softwares and Servers = 100000 INR.
Total Cost=8000000 INR.

We found significant difference of almost 30 lakhs of rupees savings to XYZ company if They Choose .NET.

Wednesday, April 6, 2011

AutoEventWireUp

AutoEventWireUp attribute in asp.net is used to call the Page_Load and Page_InIt methods automatically
by setting AutoEventWireUp=true;
By default AutoEventWireup set to true in machine.config and hence at the page level it is set to false
If you set AutoEventWireUp=true at page level then Page_Load and Page_InIt will be executed twice.

Sign up for .Net Training Bangalore