ViewState(”SomeVar”) = txtFirstName.text;
//Retrieve the value from ViewState object after the PostBack
String strFirstName = ViewState(”SomeVar”).ToString();
The main purpose of using access specifiers is to provide security to the applications. The availability (scope) of the member objects of a class may be controlled using access specifiers.
4. PROTECTEDpublic partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
SqlDataAdapter da;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
filldata();
}
}
public void filldata()
{
string str = “select * from login”;
da = new SqlDataAdapter(str,con);
ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string uname=GridView1.Rows[0].Cells[2].Text;
string qyry = “delete from login where uname=’”+uname+”‘”;
da = new SqlDataAdapter(qyry,con);
ds = new DataSet();
da.Fill(ds);
filldata();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
filldata();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtunam = (TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0];
TextBox txtpassword = (TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0];
TextBox txtconfirmpwd = (TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0];
TextBox txtemail = (TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0];
//string qry = “update login set password=’”+txtpassword.Text+”‘,confirm_password=’”+txtconfirmpwd.Text+”‘,email=’”+txtemail.Text+”‘where uname=’”+txtunam.Text+”‘”;
string qryy = “update login set password=’”+txtpassword.Text+”‘,confirm_password=’”+txtconfirmpwd.Text+”‘,email=’”+txtemail.Text+”‘where uname=’”+txtunam.Text+”‘”;
da = new SqlDataAdapter(qryy, con);
ds = new DataSet();
da.Fill(ds);
GridView1.EditIndex = -1;
filldata();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
filldata();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
filldata();
}
}
———————————————————————————————————-
In .aspx side you need to add a GridView data control.
for update/delete you have to define the datakey in gridview at aspx side:
———————————————————————————————————–
<form id=”form1″ runat=”server”>
<div>
<asp:GridView ID=”GridView1″ runat=”server” AllowPaging=”True” OnPageIndexChanging=”GridView1_PageIndexChanging”
OnRowCancelingEdit=”GridView1_RowCancelingEdit” OnRowDeleting=”GridView1_RowDeleting”
OnRowEditing=”GridView1_RowEditing” OnRowUpdating=”GridView1_RowUpdating” OnSelectedIndexChanged=”GridView1_SelectedIndexChanged”
PageSize=”3″ Style=”z-index: 100; left: 0px; position: absolute; top: 0px”>
<Columns>
<asp:CommandField ShowEditButton=”True” />
<asp:CommandField ShowDeleteButton=”True” />
</Columns>
</asp:GridView>
</div>
</form>
MSIL is the name given to the intermediate language in .NET Framework Beta, 1.0 and 1.1. From version 2.0 onwards, the intermediate language is called CIL. We can say, MSIL is the old name. MSIL stands for Microsoft Intermediate Language. CIL stands for Common Intermediate Language. Its actually a low level human readable language implementation of CLI. There is not much difference between the two. Compilers like vbc.exe and csc.exe compile the code into intermediate language. CIL is the name submitted by Microsoft to the European Computer Manufacturer’s Association(ECMA) as a standard.
In any object Oriented language, an object is the backbone of everything that we see. A class is a blueprint that describes how an instance of it (object) will behave. To create a class, we define it in a “Code File”, with an extension *.cs or *.vb. We make use of the keyword class.
ExampleLets create a class named Laptoppublic class Laptop{ private string sbrand; public Laptop() {} public Laptop(string name) { sbrand = name; }}From our code that references this class, we write…Laptop lp = new Laptop(”Lenovo”); //Passing a variable to the class constructor
Once the class object is created, the object may be used to invoke the member functions defined within the class. We may allocate any number of objects using the new keyword. The new keyword returns a reference to an object on the heap. This reference is not to the actual object itself. The variable being refered is stored on a stack for usage in the application. When we allocate an object to a heap, its managed by the .NET runtime. The garbage collector takes care of the object by removing it from the heap, when it is no longer reachable by any part of the code.
Both Overriding and Shadowing are ways to alter the behaviour of members of a base class. Shadowing is a VB.NET concept. In C#, this concept is called Hiding, though there is a difference between the two.When we do shadowing, we provide a new implementation to the base class member without overriding it. We may shadow a base class member in a derived class, by using the keyword shadows. The access level, return type, and the signature (means the datatypes of the arguments passed & the order of the types) of the derived class members which are shadowed, may differ from the base class.
In C#, we may achieve shadowing using the keyword new. However, when Hiding in C#, the access level, the signature, return type of the derived class must be same as the base class. Overriding is the concept of providing a new implementation of derived class member as compared to its based class. In VB.NET, we do overriding using the overrides keyword, while in C#, overriding is achieved using the override keyword. For a class member to be overridable, we use the keyword virtual while defining it (in C#), and we use the keyword overridable (in VB.NET), though if we leave out specifying the overridable keyword, the member is overridable by default.
Structures and Enumerations are Value-Types. This means, the data that they contain is stored as a stack on the memory. Classes are Reference-Types, means they are stored as a heap on the memory.Structures are implicitly derived from a class called System.ValueType. The purpose of System.ValueType is to override the virtual methods defined by System.Object. So when the runtime encounters a type derived from System.ValueType, then stack allocation is achieved. When we allocate a structure type, we may also use the new keyword. We may even make a constructor of a structure, but, remember, A No-argument constructor for a structure is not possible. The structure’s constructor should always have a parameter.
So if we define the following structurestruct MyStruct{ public int y,z;} and we create a structure type MyStruct st = new MyStruct();
In case of a class, no-argument constructors are possible. Class is defined using the class keyword.
A struct cannot have an instance field, whereas a class can.
class A{int x = 5; //No error …}struct{int x = 5; //Syntax Error }
A class can inherit from one class (Multiple inheritance not possible). A Structure cannot inherit from a structure.
Enum is the keyword used to define an enumeration. An enumeration is a distinct type consisting of a set of named constants called the enumerator list. Every enumeration has an underlying type. The default type is “int”. Note: char cant be the underlying data type for enum. First value in enum has value 0, each consequent item is increased by 1.
enum colors {red, green, blue, yellow};Here, red is 0, green is 1, blue is 2 and so on.An explicit casting is required to convert an enum value to its underlying typeint x = (int)colors.yellow;
The old ADO (ActiveX Data Object) has evolved to ADO.NET in the .NET Framework. The ADO.NET object is a lightweight object. The ADO Recordset was a huge object in ADO. It provided the ability to support multiple types of cursors. It provided fast lightweight “firehose” cursor and also supported a disconnected client-side cursor that supported tracking, optimistic locking, and automatic batch updates of a central database. However, all of this functionality was difficult to customize.
ADO.NET breaks the functionality of the ADO object to multiple classes, thereby allowing a focused approach to developing code. The ADO.NET DataReader is equivalent to the “firehose” cursor. The DataSet is a disconnected cache with tracking and control binding functionality. The DataAdapter provides the ability to completely customize how the central data store is updated with the changes to a DataSet.
Major difference: Classic ASP is Interpreted. ASP.NET is Compiled. If code is changed, ASP.NET recompiles, otherwise does’nt.
Other differences: ASP works with VB as the language. ASP.NET works with VB.NET & C# as the languages (Also supported by other languages that run on the .NET Framework). ASP.NET is the web technology that comes with the Microsoft .NET Framework. The main process in ASP.NET is called aspnet_wp.exe that accesses system resources. ASP.NET was launched in 2002 with version 1.0. Subsequent versions are 1.1 and version 2.0. ASP.NET is built up using thousands of objects, ordered in the System namespace. When an ASP.NET class is compiled, its called an assembly. In Classic ASP, complex functionalities are achieved using COM components, that are nothing but component objects created using VB 6, C++ etc, and are usually in a DLL format. These components provide an exposed interface to methods in them, to the objects that reference these components. Last version of classic ASP is version 3.0. ASP has 7 main objects – Application, ASPError, ObjectContext, Request, Response, Server, Session.
© PHPInterviewQuestion.com 2009 - 2010