Search This Blog

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