Thursday, December 31, 2009

Setting Up PayPal Sandbox To Our Web Forms

I had a fair bit of trouble getting the sandbox setup properly for paypal so I thought I would put some steps down to make it a bit more easier for anyone just getting started with setting up the pay pal sandbox.

1 - Go to https://developer.paypal.com/ and click the sign up now button. create an account (your username must be a different one if you have a paypal account)

2 - Click on Test Accounts, and add a business and personal account (note that if you are an australian you cant get the API keys without selecting US from the where do you live dropdown). Take note of the passwords that you use. When you create an account it creates a test bank account and test credit card for you to test your code with. You can also take note of these details for use later on in your testing.

3 - Click on API credentials, and take note of your API account, username, password and Signature. These are obviously used within your code config.

4 - Click on Test Accounts, and making sure your business account is selected, click on the enter sandbox test site button.

5 - Sign into your test site with your business account users details, your business accounts username should already be pre-filled in on the login form. Note that you must login with your business account details and not your API credentials.

6 - In the My Account Overview page, click on the step buttons to confirm your details and setup the api permissions.

7 - Most of the standard methods are activated once you have done this, but some are not. To check your api permissions click on my account/profile to go to your profile summary, then in your account information links click on API Access. Check the boxes next to the API's you wish to use, then click submit.

8 - You will prolly need some funds in your account if you are using payment methods such as mass pay, so click the Add Funds button and add some cash. Note that this is for testing use only and the money transfer is from a fictional bank.

9- These funds that you transferred need to be cleared, go to my accounts and scroll down to the bottom, you will see the fund transfers in the list, click on details link for that transaction, then click on clear transaction to complete the process.

That should be it, double check you have your API credentials setup properly in your code and you should be able to hit the sandbox for testing.

happy coding :)

Friday, December 18, 2009

what is the difference between .net2.0 and .net3.5

The .NET Framework 3.0 is Microsoft's managed code programming model. It is a superset of the .NET Framework 2.0, combining .NET Framework 2.0 components with new technologies for building applications that have visually stunning user experiences, seamless and secure communication, and the ability to model a range of business processes. In addition to the .NET Framework 2.0, it includes Windows Presentation Foundation (WPF), Windows Workflow Foundation (WF), Windows Communication Foundation (WCF), and Windows CardSpace.

Net 3.0 is an add-on to .Net 2.0. It contains three
Libraries for Windows
Presentation Foundation (WPF), Windows Workflow Foundation
(WF) and Windows
Communication Foundation (WCF) (and Windows Cardspace).
You can use these in
Visual Studio 2005 by adding extensions.

.Net 3.5 is the next .Net version after 2.0 shipped with
Visual Studio 2008


.NET 3.5 has LINQ, ASP.NET AJAX, new controls, richer WCF support, and a few other features that aren't in .NET 3.0. For server/asp.net scenarios I'd probably always recommend going with .NET 3.5. For client scenarios, .NET 3.0 is interesting to target since is pre-installed on all versions of Windows Vista - so you have good deployment of the runtime.


Note that all applications that target .NET 3.0 or .NET 2.0 will work run on .NET 3.5. You can't use the new features in .NET 3.5 if you target .NET 3.0 - but your application will obviously still work

What are the differences between Dataset and DataReader


Dataset is in memory representation of the Database. where 
you can create tables, relations between tables, add 
primary key to tables and also manipulate the data 
retrieved form the database. It allows us to work in 
connection less environment.
 
Datareader is like forward only readonly cursor, which is 
used to retrieve data. data manipulation is not possible 
while using datareader. datareader continously keeps the 
connection open.
 
A ds (dataset) can be used when the connection is closed.
A dr (datareader) needs the connection open to be used.
A ds can be used to modify or delete or insert data in the 
database. 
A data reader can be used only to read data
 
A ds can let you access the info on any order at any time.
A dr lets you access the info only one time per item and 
only in a sequential order.
 
A ds data can be loaded in longer time than a dr can be 
loaded at.
 
A ds can contain separated and structured data from several 
database tables. 
A dr can contain data in one register per item, that 
register can include data from serveral tables id the sql 
select statement so indicates, but it has no separate 
structure per table.


Thursday, December 17, 2009

Check All Checkbox In GridView To Bulk Edit Or Update ASP.NET C# NET

 chkselect all put autopostback=true;
 
protected void chkSelectAll_CheckedChanged
                               (object sender, EventArgs e)
{
 CheckBox chkAll = 
    (CheckBox)GridView1.HeaderRow.FindControl("chkSelectAll");
 if (chkAll.Checked == true)
 {
   foreach (GridViewRow gvRow in GridView1.Rows)
   {
    CheckBox chkSel = 
         (CheckBox)gvRow.FindControl("chkSelect");
    chkSel.Checked = true;
    TextBox txtname = (TextBox)gvRow.FindControl("txtName");
    TextBox txtlocation = (TextBox)gvRow.FindControl("txtLocation");
    txtname.ReadOnly = false;
    txtlocation.ReadOnly = false;
    txtname.ForeColor = System.Drawing.Color.Black;
    txtlocation.ForeColor = System.Drawing.Color.Black;
   }
 }
 else
 {
  foreach (GridViewRow gvRow in GridView1.Rows)
  {
   CheckBox chkSel = (CheckBox)gvRow.FindControl("chkSelect");
   chkSel.Checked = false;
   TextBox txtname = (TextBox)gvRow.FindControl("txtName");
   TextBox txtlocation = (TextBox)gvRow.FindControl("txtLocation");
   txtname.ReadOnly = true;
   txtlocation.ReadOnly = true;
   txtname.ForeColor = System.Drawing.Color.Blue;
   txtlocation.ForeColor = System.Drawing.Color.Blue;
   }
  }
}

Wednesday, December 16, 2009

using error Provider for Registration Page using windowes Applications

errorProvider1.Clear();
            if (txtName.Text == "")
            {
                errorProvider1.SetError(txtName, "Enter your Name");
                return;
            }
            if (txtUser.Text == "")
            {
                errorProvider1.SetError(txtUser , "Enter UserName");
                return;
            }
            if (txtPwd.Text == "")
            {
                errorProvider1.SetError(txtPwd , "Enter your Password");
                return;
            }
            if (txtContact.Text == "")
            {
                errorProvider1.SetError(txtContact, "Enter your Contact Number");
                return;
            }
            if (txtAddress.Text == "")
            {
                errorProvider1.SetError(txtAddress, "Enter your Address");
                return;
            }
            string gender;
            if (rbFemale.Checked == true)
            {
                gender = "Female";
            }
            else
            {
                gender = "Male";
            }
            try
            {
                d.command("insert into watermarking values('" + txtName.Text + "','" + cbAge.SelectedItem.ToString() + "','" + gender + "','" + txtAddress.Text + "','" + txtContact.Text + "','" + txtUser.Text + "','" + txtPwd.Text + "')");
                MessageBox.Show("succcessfully saved","message");
                txtName.Text = "";
                cbAge.SelectedIndex = 0;
                txtContact.Text = "";
                txtAddress.Text = "";
                txtUser.Text = "";
                txtPwd.Text = "";
                txtConfirm.Text = "";
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            txtName.Text = "";
            cbAge.SelectedIndex = 0;
            txtContact.Text = "";
            txtAddress.Text = "";
            txtUser.Text = "";
            txtPwd.Text = "";
            txtConfirm.Text = "";

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtConfirm_TextChanged(object sender, EventArgs e)
        {
            if (txtConfirm.Text != txtPwd.Text)
            {
                errorProvider1.SetError(txtConfirm, "Please Enter Same Password");
            }
            else
            {
                errorProvider1.Clear();

            }
        }
    }
}

Thursday, December 10, 2009

inserting And retrive The data using Xml

   
        jobs for all Catagories
        View Jobs

   

   
        View Jobs
       
       

        Applynow
       

        Home
   

   
        Select Your Job
       
       

        Give Your Name
       

       
       

        Email id
       

       
       

        Apply Now
       

       

        Label
   

   
   




Coding
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Mobile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.MobileControls;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class applyjobs : System.Web.UI.MobileControls.MobilePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            DataSet ds = new DataSet();
            ds.ReadXml(MapPath("jobs1.xml"));
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                List1.Items.Add(dr["catagory_Text"].ToString());
                SelectionList1.Items.Add(dr["catagory_Text"].ToString());
            }
        }
    }
    protected void btnApply_Click(object sender, EventArgs e)
    {
        DataSet ds1 = new DataSet();
        ds1.ReadXml(MapPath("Appiled.xml"));
        DataRow dr = ds1.Tables[0].NewRow();
        dr[0] = txtusername.Text;
        dr[1] = txtEmail.Text;
        dr[2] = SelectionList1.Items[SelectionList1.SelectedIndex].Value;
        ds1.Tables[0].Rows.Add(dr);
        ds1.WriteXml(MapPath ("Appiled.xml"));
        lblmsg.Visible = true;
        lblmsg.Text = "SucessFully Submitted Your Deatails";

    }
}

Tuesday, December 8, 2009

C# Interview Questions


This is a list of questions I have gathered from other sources and created myself over a period of time from my experience, many of which I felt where incomplete or simply wrong.  I have finally taken the time to go through each question and correct them to the best of my ability.  However, please feel free to post feedback to challenge, improve, or suggest new questions.  I want to thank those of you that have contributed quality questions and corrections thus far.
There are some question in this list that I do not consider to be good questions for an interview.  However, they do exist on other lists available on the Internet so I felt compelled to keep them easy access.
General Questions
  1. Does C# support multiple-inheritance?
    No.
     
  2. Who is a protected class-level variable available to?
    It is available to any sub-class (a class inheriting this class).
     
  3. Are private class-level variables inherited?
    Yes, but they are not accessible.  Although they are not visible or accessible via the class interface, they are inherited.
     
  4. Describe the accessibility modifier “protected internal”.
    It is available to classes that are within the same assembly and derived from the specified base class.
     
  5. What’s the top .NET class that everything is derived from?
    System.Object.
     
  6. What does the term immutable mean?
    The data value may not be changed.  Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.

     
  7. What’s the difference between System.String and System.Text.StringBuilder classes?
    System.String is immutable.  System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.
     
  8. What’s the advantage of using System.Text.StringBuilder over System.String?
    StringBuilder is more efficient in cases where there is a large amount of string manipulation.  Strings are immutable, so each time a string is changed, a new instance in memory is created.
     
  9. Can you store multiple data types in System.Array?
    No.
     
  10. What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
    The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array.  The CopyTo() method copies the elements into another existing array.  Both perform a shallow copy.  A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array.  A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identacle object.
     
  11. How can you sort the elements of the array in descending order?
    By calling Sort() and then Reverse() methods.
     
  12. What’s the .NET collection class that allows an element to be accessed using a unique key?
    HashTable.
     
  13. What class is underneath the SortedList class?
    A sorted HashTable.
     
  14. Will the finally block get executed if an exception has not occurred?­
    Yes.
     
  15. What’s the C# syntax to catch any possible exception?
    A catch block that catches the exception of type System.Exception.  You can also omit the parameter data type in this case and just write catch {}.
     
  16. Can multiple catch blocks be executed for a single try statement?
    No.  Once the proper catch block processed, control is transferred to the finally block (if there are any).
     
  17. Explain the three services model commonly know as a three-tier application.
    Presentation (UI), Business (logic and underlying code) and Data (from storage or other sources).
     
Class Questions
  1. What is the syntax to inherit from a class in C#?
    Place a colon and then the name of the base class.
    Example: class MyNewClass : MyBaseClass
     
  2. Can you prevent your class from being inherited by another class?
    Yes.  The keyword “sealed” will prevent the class from being inherited.
     
  3. Can you allow a class to be inherited, but prevent the method from being over-ridden?
    Yes.  Just leave the class public and make the method sealed.
     
  4. What’s an abstract class?
    A class that cannot be instantiated.  An abstract class is a class that must be inherited and have the methods overridden.  An abstract class is essentially a blueprint for a class without any implementation.
     
  5. When do you absolutely have to declare a class as abstract?
    1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
    2. 
    When at least one of the methods in the class is abstract.
     
  6. What is an interface class?
    Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes.
     
  7. Why can’t you specify the accessibility modifier for methods inside the interface?
    They all must be public, and are therefore public by default.
     
  8. Can you inherit multiple interfaces?
    Yes.  .NET does support multiple interfaces.
     
  9. What happens if you inherit multiple interfaces and they have conflicting method names?
    It’s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay.
    To Do: Investigate
     
  10. What’s the difference between an interface and abstract class?
    In an interface class, all methods are abstract - there is no implementation.  In an abstract class some methods can be concrete.  In an interface class, no accessibility modifiers are allowed.  An abstract class may have accessibility modifiers.
     
  11. What is the difference between a Struct and a Class?
    Structs are value-type variables and are thus saved on the stack, additional overhead but faster retrieval.  Another difference is that structs cannot inherit.
     
Method and Property Questions
  1. What’s the implicit name of the parameter that gets passed into the set method/property of a class?
    Value.  The data type of the value parameter is defined by whatever data type the property is declared as.
     
  2. What does the keyword “virtual” declare for a method or property?
    The method or property can be overridden.
     
  3. How is method overriding different from method overloading?
    When overriding a method, you change the behavior of the method for the derived class.  Overloading a method simply involves having another method with the same name within the class.
     
  4. Can you declare an override method to be static if the original method is not static?
    No.  The signature of the virtual method must remain the same.  (Note: Only the keyword virtual is changed to keyword override)
     
  5. What are the different ways a method can be overloaded?
    Different parameter data types, different number of parameters, different order of parameters.
     
  6. If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?
    Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.
     
Events and Delegates
  1. What’s a delegate?
    A delegate object encapsulates a reference to a method.
     
  2. What’s a multicast delegate?
    A delegate that has multiple handlers assigned to it.  Each assigned handler (method) is called.
     
XML Documentation Questions
  1. Is XML case-sensitive?
    Yes.
     
  2. What’s the difference between // comments, /* */ comments and /// comments?
    Single-line comments, multi-line comments, and XML documentation comments.
     
  3. How do you generate documentation from the C# file commented properly with a command-line compiler?
    Compile it with the /doc switch.
     
Debugging and Testing Questions
  1. What debugging tools come with the .NET SDK?
    1.   CorDBG – command-line debugger.  To use CorDbg, you must compile the original C# file using the /debug switch.
    2.   DbgCLR – graphic debugger.  Visual Studio .NET uses the DbgCLR.
     
  2. What does assert() method do?
    In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false.  The program proceeds without any interruption if the condition is true.
     
  3. What’s the difference between the Debug class and Trace class?
    Documentation looks the same.  Use Debug class for debug builds, use Trace class for both debug and release builds.
     
  4. Why are there five tracing levels in System.Diagnostics.TraceSwitcher?
    The tracing dumps can be quite verbose.  For applications that are constantly running you run the risk of overloading the machine and the hard drive.  Five levels range from None to Verbose, allowing you to fine-tune the tracing activities.
     
  5. Where is the output of TextWriterTraceListener redirected?
    To the Console or a text file depending on the parameter passed to the constructor.
     
  6. How do you debug an ASP.NET Web application?
    Attach the aspnet_wp.exe process to the DbgClr debugger.
     
  7. What are three test cases you should go through in unit testing?
    1.       Positive test cases (correct data, correct output).
    2.       Negative test cases (broken or missing data, proper handling).
    3.       Exception test cases (exceptions are thrown and caught properly).
     
  8. Can you change the value of a variable while debugging a C# application?
    Yes.  If you are debugging via Visual Studio.NET, just go to Immediate window.
     
ADO.NET and Database Questions
  1. What is the role of the DataReader class in ADO.NET connections?
    It returns a read-only, forward-only rowset from the data source.  A DataReader provides fast access when a forward-only sequential read is needed.
  2.  
  3. What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?
    SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix.  OLE-DB.NET is a .NET layer on top of the OLE layer, so it’s not as fastest and efficient as SqlServer.NET.
     
  4. What is the wildcard character in SQL?
    Let’s say you want to query database with LIKE for all employees whose name starts with La. The wildcard character is %, the proper query with LIKE would involve ‘La%’.
     
  5. Explain ACID rule of thumb for transactions.
    A transaction must be:
    1.       Atomic - it is one unit of work and does not dependent on previous and following transactions.
    2.       Consistent - data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t.
    3.       Isolated - no transaction sees the intermediate results of the current transaction).
    4.       Durable - the values persist if the data had been committed even if the system crashes right after.
     
  6. What connections does Microsoft SQL Server support?
    Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and password).
     
  7. Between Windows Authentication and SQL Server Authentication, which one is trusted and which one is untrusted?
    Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.
     
  8. What does the Initial Catalog parameter define in the connection string?
    The database name to connect to.
     
     
  9. What does the Dispose method do with the connection object?
    Deletes it from the memory.
    To Do: answer better.  The current answer is not entirely correct.
     
  10. What is a pre-requisite for connection pooling?
    Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings.  The connection string must be identical.
     
Assembly Questions
  1. How is the DLL Hell problem solved in .NET?
    Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly.
     
  2. What are the ways to deploy an assembly?
    An MSI installer, a CAB archive, and XCOPY command.
     
  3. What is a satellite assembly?
    When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.
     
  4. What namespaces are necessary to create a localized application?
    System.Globalization and System.Resources.
     
  5. What is the smallest unit of execution in .NET?
    an Assembly.
     
  6. When should you call the garbage collector in .NET?
    As a good rule, you should not call the garbage collector.  However, you could call the garbage collector when you are done using a large object (or set of objects) to force the garbage collector to dispose of those very large objects from memory.  However, this is usually not a good practice.
     
  7. How do you convert a value-type to a reference-type?
    Use Boxing.
     
  8. What happens in memory when you Box and Unbox a value-type?
    Boxing converts a value-type to a reference-type, thus storing the object on the heap.  Unboxing converts a reference-type to a value-type, thus storing the value on the stack.

ASP.NET Interview Questions

ASP.NET Interview Questions
This is a list of questions I have gathered and created over a period of time from my experience, many of which I felt where incomplete or simply wrong.  I have finally taken the time to go through each question and correct them to the best of my ability.  However, please feel free to post feedback to challenge, improve, or suggest new questions.  I want to thank those of you that have contributed quality questions and corrections thus far.
There are some questions in this list that I do not consider to be good questions for an interview.  However, they do exist on other lists available on the Internet so I felt compelled to keep them here for easy access.
  1. Describe the role of inetinfo.exe, aspnet_isapi.dll andaspnet_wp.exe in the page loading process.
    inetinfo.exe is theMicrosoft IIS server running, handling ASP.NET requests among other things.When an ASP.NET request is received (usually a file with .aspx extension), the ISAPI filter aspnet_isapi.dll takes care of it by passing the request tothe actual worker process aspnet_wp.exe.
     
  2. What’s the difference between Response.Write() andResponse.Output.Write()?
    Response.Output.Write() allows you to write formatted output.
     
  3. What methods are fired during the page load?
    Init() - when the page is instantiated
    Load() - when the page is loaded into server memory
    PreRender() - the brief moment before the page is displayed to the user as HTML
    Unload() - when page finishes loading.
     
  4. When during the page processing cycle is ViewState available?
    After the Init() and before the Page_Load(), or OnLoad() for a control.
     
  5. What namespace does the Web page belong in the .NET Framework class hierarchy?
    System.Web.UI.Page
     
  6. Where do you store the information about the user’s locale?
    System.Web.UI.Page.Culture
     
  7. What’s the difference between Codebehind="MyCode.aspx.cs" andSrc="MyCode.aspx.cs"?
    CodeBehind is relevant to Visual Studio.NET only.
     
  8. What’s a bubbled event?
    When you have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its constituents.
     
  9. Suppose you want a certain ASP.NET function executed on MouseOver for a certain button.  Where do you add an event handler?
    Add an OnMouseOver attribute to the button.  Example: btnSubmit.Attributes.Add("onmouseover","someClientCodeHere();");
     
  10. What data types do the RangeValidator control support?
    Integer, String, and Date.
     
  11. Explain the differences between Server-side and Client-side code?
    Server-side code executes on the server.  Client-side code executes in the client's browser.
     
  12. What type of code (server or client) is found in a Code-Behind class?
    The answer is server-side code since code-behind is executed on the server.  However, during the code-behind's execution on the server, it can render client-side code such as JavaScript to be processed in the clients browser.  But just to be clear, code-behind executes on the server, thus making it server-side code.
     
  13. Should user input data validation occur server-side or client-side?  Why?
    All user input data validation should occur on the server at a minimum.  Additionally, client-side validation can be performed where deemed appropriate and feasable to provide a richer, more responsive experience for the user.
     
  14. What is the difference between Server.Transfer and Response.Redirect?  Why would I choose one over the other?
    Server.Transfer transfers page processing from one page directly to the next page without making a round-trip back to the client's browser.  This provides a faster response with a little less overhead on the server.  Server.Transfer does not update the clients url history list or current url.  Response.Redirect is used to redirect the user's browser to another page or site.  This performas a trip back to the client where the client's browser is redirected to the new page.  The user's browser history list is updated to reflect the new address.
     
  15. Can you explain the difference between an ADO.NET Dataset and an ADO Recordset?
    Valid answers are:
    · 
    A DataSet can represent an entire relational database in memory, complete with tables, relations, and views.
    ·  A DataSet is designed to work without any continuing connection to the original data source.
    ·  Data in a DataSet is bulk-loaded, rather than being loaded on demand.
    ·  There's no concept of cursor types in a DataSet.
    ·  DataSets have no current record pointer You can use For Each loops to move through the data.
    ·  You can store many edits in a DataSet, and write them to the original data source in a single operation.
    ·  Though the DataSet is universal, other objects in ADO.NET come in different versions for different data sources.
     
  16. What is the Global.asax used for?
    The Global.asax (including the Global.asax.cs file) is used to implement application and session level events.
     
  17. What are the Application_Start and Session_Start subroutines used for?
    This is where you can set the specific variables for the Application and Session objects.
     
  18. Can you explain what inheritance is and an example of when you might use it?
    When you want to inherit (use the functionality of) another class.  Example: With a base class named Employee, a Manager class could be derived from the Employee base class.
     
  19. Whats an assembly?
    Assemblies are the building blocks of the .NET framework. Overview of assemblies from MSDN
     
  20. Describe the difference between inline and code behind.
    Inline code written along side the html in a page. Code-behind is code written in a separate file and referenced by the .aspx page.
     
  21. Explain what a diffgram is, and a good use for one?
    The DiffGram is one of the two XML formats that you can use to render DataSet object contents to XML.  A good use is reading database data to an XML file to be sent to a Web Service.
     
  22. Whats MSIL, and why should my developers need an appreciation of it if at all?
    MSIL is the Microsoft Intermediate Language. All .NET compatible languages will get converted to MSIL.  MSIL also allows the .NET Framework to JIT compile the assembly on the installed computer.
     
  23. Which method do you invoke on the DataAdapter control to load your generated dataset with data?
    The Fill() method.
     
  24. Can you edit data in the Repeater control?
    No, it just reads the information from its data source.
     
  25. Which template must you provide, in order to display data in a Repeater control?
    ItemTemplate.
     
  26. How can you provide an alternating color scheme in a Repeater control?
    Use the AlternatingItemTemplate.
     
  27. What property must you set, and what method must you call in your code, in order to bind the data from a data source to the Repeater control?
    You must set the DataSource property and call the DataBind method.
     
  28. What base class do all Web Forms inherit from?
    The Page class.
     
  29. Name two properties common in every validation control?
    ControlToValidate property and Text property.
     
  30. Which property on a Combo Box do you set with a column name, prior to setting the DataSource, to display data in the combo box?
    DataTextField property.
     
  31. Which control would you use if you needed to make sure the values in two different controls matched?
    CompareValidator control.
     
  32. How many classes can a single .NET DLL contain?
    It can contain many classes.
     
Web Service Questions
  1. What is the transport protocol you use to call a Web service?
    SOAP (Simple Object Access Protocol) is the preferred protocol.
     
  2. True or False: A Web service can only be written in .NET?
    False
     
  3. What does WSDL stand for?
    Web Services Description Language.
     
  4. Where on the Internet would you look for Web services?
    http://www.uddi.org
     
  5. True or False: To test a Web service you must create a Windows application or Web application to consume this service?
    False, the web service comes with a test page and it provides HTTP-GET method to test.
     
State Management Questions
  1. What is ViewState?
    ViewState allows the state of objects (serializable) to be stored in a hidden field on the page.  ViewState is transported to the client and back to the server, and is not stored on the server or any other external source.  ViewState is used the retain the state of server-side objects between postabacks.
     
  2. What is the lifespan for items stored in ViewState?
    Item stored in ViewState exist for the life of the current page.  This includes postbacks (to the same page).
     
  3. What does the "EnableViewState" property do?  Why would I want it on or off?
    It allows the page to save the users input on a form across postbacks.  It saves the server-side values for a given control into ViewState, which is stored as a hidden value on the page before sending the page to the clients browser.  When the page is posted back to the server the server control is recreated with the state stored in viewstate.
     
  4. What are the different types of Session state management options available with ASP.NET?
    ASP.NET provides In-Process and Out-of-Process state management.  In-Process stores the session in memory on the web server.  This requires the a "sticky-server" (or no load-balancing) so that the user is always reconnected to the same web server.  Out-of-Process Session state management stores data in an external data source.  The external data source may be either a SQL Server or a State Server service.  Out-of-Process state management requires that all objects stored in session are serializable.

Monday, December 7, 2009

Error: Debugging Failed Because Integrated Windows Authentication Is Not Enable

Error: Debugging Failed Because Integrated Windows Authentication Is Not Enabled

Authentication of the user who requested debugging was prevented by an authentication error. This can occur when you try to step into a Web application or an XML Web service. One cause of this error is that integrated Windows authentication is not enabled. To enable it, follow the steps in "To enable integrated Windows authentication."
If you have enabled integrated Windows authentication and this error still appears, it is possible that this error is caused because Digest Authentication for Windows Domain Servers is enabled. In this situation you should contact with your network administrator.

To enable integrated Windows authentication

  1. Log on to the Web server by using an administrator account.
  2. Click Start and then click Control Panel.
  3. In Control Panel, double-click Administrative Tools.
  4. Double-click Internet Information Services.
  5. Click the Web server node.
    A Web Sites folder opens underneath the server name.
  6. You can configure authentication for all Web sites or for individual Web sites. To configure authentication for all Web sites, right-click the Web Sites folder and then click Properties. To configure authentication for an individual Web site, open the Web Sites folder, right-click the individual Web site, and then click Properties.
    The Properties dialog box is displayed.
  7. Click the Directory Security tab.
  8. In the Anonymous access and authentication control section, click Edit.
    The Authentication Methods dialog box is displayed.
  9. Under Authenticated access, select Integrated Windows authentication.
  10. Click OK to close the Authentication Methods dialog box.
  11. Click OK to close the Properties dialog box.
  12. Close the Internet Information Services window.

To enable integrated Windows authentication in Windows Vista/IIS 7

  1. Log on to the Web server by using an administrator account.
  2. Turn on Windows Authentication and II6 Management Compatibility, if you have not previously done this, by following these steps:
    1. Click Start, click Control Panel and then click Programs.
    2. Under Programs and Features, click Turn Windows features on or off.
      The User Access Control dialog box appears and prompts you for permission to continue.
    3. Click Continue.
      The Windows Features dialog box appears.
    4. In the feature list, expand the Internet Information Services node.

    5. Under Internet Information Services, expand the World Wide Web Services node.
    6. Under World Wide Web Services, click Security.
    7. Click Windows Authentication.
    8. Under Internet Information Services, expand the Web Management Tools node.
    9. Under Web Management Tools, expand the IIS 6 Management Compatibility node, and select the IIS 6 Metabase and IIS 6 Configuration Compatibility check box.
    10. Under Web Management Tools, select IIS Management Console and Click OK.
    11. Restart the computer for these changes to take effect.
  3. Click Start and then, click Control Panel.
  4. Click Classic View, and then double-click Administrative Tools.
  5. In the Name column and double-click Internet Information Services (IIS) Manager.
  6. In the Connections column, expand the node for your server.
    A Web Sites folder opens underneath the server name.
  7. Expand the Web Sites node and click the Web site for which you want to enable integrated Windows authentication.
  8. The title of the center pane changes to the name of the Web site that you selected. In this pane, under the IIS heading, double-click Authentication.
    The title of the pane changes to Authentication.
  9. In the Authentication pane, in the Name column, right-click Windows Authentication and then click Enable.
  10. Close the Internet Information Services (IIS) Manager window.

Thursday, December 3, 2009

SQl Server Quieries

select a.donorname,b.ename from donor_details a,emp_details b

select top 2 * from emp_details order by username

select (sum(sal)) from emp_details

select (max(sal)) from emp_details

select distinct(desg) from emp_details

select * from emp_details where eid in (4 , 5,6)

select * from emp_details where eid =4 or eid =18 or eid=6

 select * from emp_details where ename ='bhargav' and password='kiran'

select count(0) as records from emp_details

select ename, email ,count(*)from emp_details group by ename , email

  select ename, email ,count(*)from emp_details group by ename

select distinct ename,email from emp_details group by ename , email

 select  ename from emp_details group by ename

select  ename,email,desg from emp_details group by ename , email ,desg
having desg = 't2'

SQL SERVER – Definition, Comparison and Difference between HAVING and WHERE Clause

In recent interview sessions in hiring process I asked this question to every prospect who said they know basic SQL. Surprisingly, none answered me correct. They knew lots of things in details but not this simple one. One prospect said he does not know cause it is not on this Blog. Well, here we are with same topic online.
Answer in one line is : HAVING specifies a search condition for a group or an aggregate function used in SELECT statement.
HAVING can be used only with the SELECT statement. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause.
A HAVING clause is like a WHERE clause, but applies only to groups as a whole, whereas the WHERE clause applies to individual rows. A query can contain both a WHERE clause and a HAVING clause. The WHERE clause is applied first to the individual rows in the tables . Only the rows that meet the conditions in the WHERE clause are grouped. The HAVING clause is then applied to the rows in the result set. Only the groups that meet the HAVING conditions appear in the query output. You can apply a HAVING clause only to columns that also appear in the GROUP BY clause or in an aggregate function. (Reference :BOL)
Example of HAVING and WHERE in one query:
SELECT titles.pub_id, AVG(titles.price)
FROM titles INNER JOIN publishers
ON titles.pub_id = publishers.pub_id
WHERE publishers.state = 'CA'
GROUP BY titles.pub_id
HAVING AVG(titles.price) > 10

Sometimes you can specify the same set of rows using either a WHERE clause or a HAVING clause. In such cases, one method is not more or less efficient than the other. The optimizer always automatically analyzes each statement you enter and selects an efficient means of executing it. It is best to use the syntax that most clearly describes the desired result. In general, that means eliminating undesired rows in earlier clauses.

SQL SERVER – Difference between DISTINCT and GROUP BY – Distinct vs Group By

What is difference between DISTINCT and GROUP BY?
A DISTINCT and GROUP BY usually generate the same query plan, so performance should be the same across both query constructs. GROUP BY should be used to apply aggregate operators to each group. If all you need is to remove duplicates then use DISTINCT. If you are using sub-queries execution plan for that query varies so in that case you need to check the execution plan before making decision of which is faster.
Example of DISTINCT:
SELECT DISTINCT Employee, Rank
FROM Employees

Example of GROUP BY:
SELECT Employee, Rank
FROM Employees
GROUP BY Employee, Rank

Example of GROUP BY with aggregate function:
SELECT Employee, Rank, COUNT(*) EmployeeCount
FROM Employees
GROUP BY Employee, Rank

instead of trigger raising in sqlserver 2005

A trigger is a database object similar to a stored procedure that executes in response to certain actions that occur in your database environment. SQL Server 2005 is packaged with three flavors of trigger objects: AFTER, data definition language (DDL), and INSTEAD-OF.
AFTER triggers are stored procedures that occur after a data manipulation statement has occurred in the database, such as a delete statement. DDL triggers are new to SQL Server 2005, and allow you to respond to object definition level events that occur in the database engine, such as a DROP TABLE statement. INSTEAD-OF triggers are objects that will execute instead of data manipulation statements in the database engine. For example, attaching an INSTEAD-OF INSERT trigger to a table will tell the database engine to execute that trigger instead of executing the statement that would insert values into that table.




alter trigger insteadofpro2 on pro instead of delete
as begin
declare @pno int;
declare @productname varchar(50);
declare @cost varchar(50);
declare @action1 varchar(100);
select @pno=d.pno from deleted d;
select @productname=d.productname from deleted d;
select @cost=d.cost from deleted d;
select @action1='delete record insted of ';
if(@cost=10000)
begin
raiserror ('Cannot deletd where sal =3000',16,1)
rollback
end
else
begin

commit
delete from pro where pno=@pno
insert into protrigger values(@pno,@productname,@cost,@action1,getdate())
print'record delete bfore insert';
end
end

Wednesday, December 2, 2009

After /for Trigger example Using Sqlserver2005

 A trigger is a database object that is attached to a table. In many aspects it is similar to a stored procedure. As a matter of fact, triggers are often referred to as a "special kind of stored procedure." The main difference between a trigger and a stored procedure is that the former is attached to a table and is only fired when an INSERT, UPDATE or DELETE occurs. You specify the modification action(s) that fire the trigger when it is created.
The following shows how to create a trigger that displays the current system time when a row is inserted into the table to which it is attached.


create trigger trg2 on pro for
insert 
as
declare @pno int;
declare @productname varchar(50);
declare @cost varchar(50);
declare @action1 varchar(100);

select @pno =i.pno from inserted i;
select @productname =i.productname from inserted i;
select @cost =i.cost from inserted i;
select @action1 = 'inserted record after insert trigger'
insert into protrigger(pno, productname, cost, action1, time1)values (@pno, @productname, @cost, @action1, getdate());
print'after insert Trigger find';
go

Friday, November 27, 2009

C# Realtime Interview Questions

#.NET Interview Questions and Realtime Discussions ,C# Realtime Interview Questions,C# Questions for MNCs like Cap Gemini,CTS,HP,Patni,Sasken

What is the top .NET class that everything is derived from?
System.Objects

What is an abstract class?
The abstract modifier can be used with classes, methods, properties, indexers, and events.
Use the abstract modifier in a class declaration to indicate that a class is intended only to be a base class of other classes.

Abstract classes have the following features:
An abstract class cannot be instantiated.
An abstract class may contain abstract methods and accessors.
It is not possible to modify an abstract class with the sealed modifier, which means that the class cannot be inherited.
A non-abstract class derived from an abstract class must include actual implementations of all inherited abstract methods and accessors.
Use the abstract modifier in a method or property declaration to indicate that the method or property does not contain implementation.

Abstract methods have the following features:
An abstract method is implicitly a virtual method.
Abstract method declarations are only permitted in abstract classes.
Because an abstract method declaration provides no actual implementation, there is no method body; the method declaration simply ends with a semicolon and there are no braces ({ }) following the signature. For example:
public abstract void MyMethod();
________________________________________
abstract class is a prototype of a class. it is used to provide partial
class implementation. abstract class contain abstract method which can be implemented by derived class.
some rules for abstract class are following-:
1) an object of an abstract class can never be created.
2)you can not declare an abstract method outside the abstract class.
3)can not be declared sealed.

WHAT IS THE ADVANTAGE OF SERIALIZATION?
Serialization is the process of maintaing object in the form stream. it is useful in case of remoting.
Serialization is the process of converting object into byte stream which is useful to transport object(i.e remoting),persisting object(i.e files,database)
SERIALIZATION IS PROCESS OF LOADING THE OBJECT STATE IN THE FORM OF BYTE STREAMS IN DATABASE/FILE SYATEM.

Can we inherit the java class in C# class,how?
Java Programming language is not supported with .Net Framework hence you cannot inherit javaclass in C# class.Also Java has JavaByte code after compiling similar to MSIL which is similar but cannot inherit due to framework support.

Are C# destructors the same as C++ destructors?
No. They look the same but they are very different. The C# destructor syntax (with the familiar ~ character) is just syntactic sugar for an override of the System.Object Finalize method. This Finalize method is called by the garbage collector when it determines that an object is no longer referenced, before it frees the memory associated with the object. So far this sounds like a C++ destructor. The difference is that the garbage collector makes no guarantees about when this procedure happens. Indeed, the algorithm employed by the CLR garbage collector means that it may be a long time after the application has finished with the object. This lack of certainty is often termed ‘non-deterministic finalization’, and it means that C# destructors are not suitable for releasing scarce resources such as database connections, file handles etc.
To achieve deterministic destruction, a class must offer a method to be used for the purpose. The standard approach is for the class to implement the IDisposable interface. The user of the object must call the Dispose() method when it has finished with the object. C# offers the ‘using’ construct to make this easier.

What is wrapper class? is it available in c#?
Wrapper Classes are the classes that wrap up the primitive values in to a class that offer utility method to access it . For eg you can store list of int values in a vector class and access the class. Also the methods are static and hence you can use them without creating an instance . The values are immutable .
wrapper class are those class in which we can not define and call all predefined function .it is possible in java not C#.

Which tool is used to browse the classes, structs, interfaces etc. in the BCL?
wincv as in Windows Class View

How is the using() pattern useful? What is IDisposable? How does it support deterministic finalization?
The using() pattern is useful because it ensures that Dispose() will always be called when a disposable object (defined as one that implements IDisposable, and thus the Dispose() method) goes out of scope, even if it does so by an exception being thrown, and thus that resources are always released.

What happens when a C# project has more than 1 Main methods
f the project is compiled using /main switch with the compiler then the project compiles successfully.

For example:
class A
{
public static void Main(string[] args)
{
Console.WriteLine("Main in class A");
}
}

class B
{
public static void Main(string[] args)
{
Console.WriteLine("Main in class B");
}
}

Now compile with the /main switch with the C# compiler like
csc MultipleMain.cs /main:A

This will compile without error and while executing it will show Main in class A

Attempting to compile an application consisting of multiple classes with defined Main methods and not specifying the /main switch will result in a compiler error.
How do you refer parent classes in C#? A) Super B) This C) Base
This keyword is used for reffering current object and Base keyword is used for referring parrent class. so ans. is C.
Super: Super is used to Refer the Base Class in JAVA
This: This is used to Refer the Current or Child Class in C#
Base: Base is used to Refer The Parent or Base Class

What is object pooling
Defination: A performance optimization based on using collections of pre-allocated resources, such as objects or database connections
With the advent of the .NET platform, writing code that pools objects and threads has become a simple task. By using the Threading and Collections namespaces, you can create robust object pooling applications. This could also be done by implementing COM+ interop interfaces into your code.

Which method is actually called ultimately when Console.WriteLine( ) is invoked?
A) Append( )
B) AppendFormat( )
C) Tostring( )
Ans: B, AppendFormat() method is called.

What is an Assembly?
An assembly is a file that is automatically generated by the compiler upon successful compilation of every .NET application. It can be either a Dynamic Link Library or an executable file. It is generated only once for an application and upon each subsequent compilation the assembly gets updated. The entire process will run in the background of your application; there is no need for you to learn deeply about assemblies. However, a basic knowledge about this topic will help you to understand the architecture behind a .NET application.
An assembly is used by the .NET CLR (Common Language Runtime) as the smallest unit for: deployment; version control; security; type grouping and code reuse. Assemblies consists of a manifest and one or more modules and/or files like HTML, XML, images, video clips,...

An assembly can be thought of as a logical DLL and must contain a single manifest and may optionally contain type meta data, MSIL (Microsoft Intermediate Language) and resources.

Assemblies come in 2 flavors: application private and shared. Application private assemblies are used by one application only. This is the default style of assembly. Such assemblies must reside in the application folder.

Shared assemblies are meant to be used by more than one application. They must have a
globally unique name and must be defined in the GAC (Global Assembly Cache). To learn more about viewing the GAC
Basically there are two kind of assemblies when it comes to deployment.
Private Assemblies
Shared Assemblies

Private assemblies are the ones which are in your application folder itself. They can be easily and uniquely identified by their name.
These type of assemblies can be deployed simply by copying them to the bin folder of your application.

Shared Assemblies are those which can be shared by multiple applications on the machine.
For this we have to place the Shared assembly in the GAC.

Now since we can install any application or assembly created by any company, that is we install assemblies from oracle, microsoft and similarly from many other companies.

There is always a possiblity that they may use the same assembly name as your assembly name.
If such type of assemblies are placed in the GAC then we cannot uniquely identify a particular assembly.But if we give a strong name to the assmebly then it is like a unique identifier for the assembly.It is Globally unique.

Strong name consists of
1. Name of the assembly
2. Public key token
3. optionally any resources
4. Version Number

So basically to uniquely identify a particular assembly from the GAC we have to give it a strong name. Its that simple.
The Shared assembly can be deployed in to GAC by using the GACUTIL tool with the -i switch
gacutil -i assemblyname
or simply copying it to the assembly folder in the windows directory (XP) or WINNT directory(others)
Also there are Satellite Assemblies which contian only resources like strings, images etc.
Also there are dynamic assemblies which are generated on the fly dynamically.

Real world examples of abstract classes and interfaces

An abstract class is a class that you cannot create an instance of. It can provide basic functionality, but in order for that functionality to be used, one or more other classes must derive from the abstract class. One of the major benefits of abstract classes is that you can reuse code without having to retype it. That has a plethora of benefits, such as reducing bugs and making coding faster. A concrete example of an abstract class would be a class called Animal. You see many animals in real life, but there are only kinds of animals. That is, you never look at something purple and furry and say "that is an animal and there is no more specific way of defining it". Instead, you see a dog or a cat or a pig... all animals. The point is, that you can never see an animal walking around that isn't more specifically something else (duck, pig, etc.). The Animal is the abstract class and Duck/Pig/Cat are all classes that derive from that base class. Animals might provide a function called "Age" that adds 1 year of life to the animals. It might also provide an abstract method called "IsDead" that, when called, will tell you if the animal has died. Since IsDead is abstract, each animal must implement it. So, a Cat might decide it is dead after it reaches 14 years of age, but a Duck might decide it dies after 5 years of age. The abstract class Animal provides the Age function to all classes that derive from it, but each of those classes has to implement IsDead on their own.
Now, an interface is like an abstract class, except it does not contain any logic. Rather, it specifies an interface. So, there might be an interface called IFly. This might have the methods GoForward and GoDown. Those methods would not actually contain any logic... each class that implements interface IFly would have to implement those GoForward and GoDown methods. You could have classes Duck and Finch implement interface IFly. Then, if you want to keep a list of instances that can fly, you just create a list that contains items of type IFly. That way, you can add Ducks and Finches and any other instance of a class the implements IFly to the list.
So, abstract classes can be used to consolidate and share functionality, while interfaces can be used to specify what the common functionality that will be shared between different instances will be, without actually building that functionality for them. Both can help you make your code smaller, just in different ways. There are other differences between interfaces and abstract classes, but those depend on the programming language, so I won't go into those other differences here.

Or
Do you mean real-world as in "A live software system which includes  Abstract classes or interfaces" or do you mean "A contrived example which demonstrates their usefullness"?
If you mean the latter think of Vehicle as an abstract class. You can't yet do anything with it because you have no idea what it does, or how to drive it.
abstract class Vehicle{}
Vehicles could be split into morotized and pedal-powered, but still this is abstract, we still dont know what to do with it.

abstract class MotorVehicle : Vehicle {}
abstract class PedaledVehicle : Vehicle {}
You could now define a concrete (non-abstract) class, like car.
class MotorCar : MotorVehicle {}
 Intefaces come in handy you can only inherit from one base class. So imagine some vehicles are drivable, others are remote controlled, some vehicles use a stearing wheel, others dont
interface IDrivable{}
interface IHasStearingWheel{}
Now you could derive a DrivableMotorCar from its base clas, and also implement other behaviours.
class DrivableMotorCar : MotorVehicle, IDrivable, IHasStearingWheel {}


or 

I Just find a suitable reference... Pls refer to this...


http://www.codeproject.com/KB/cs/abstractsvsinterfaces.aspx

Deligates Using C#.net

A delegate in C# is similar to a function pointer in C or C++.
Using a delegate allows the programmer to encapsulate a reference to a method inside
a delegate object. The delegate object can then be passed to code which can call the
referenced method, without having to know at compile time which method will be
invoked.
using System;

          namespace Akadia.BasicDelegate

               {

                   // Declaration

                   public delegate void SimpleDelegate();

              

                   class TestDelegate

                   {

                       public static void MyFunc()

                       {

                          
              Console.WriteLine("I was called by delegate ...");

                       }

              

                       public static void Main()

                       {

                           // Instantiation

                           SimpleDelegate simpleDelegate = new SimpleDelegate(MyFunc);

              

                           // Invocation

                          
              simpleDelegate();

                       }

                   }

               }
        
 http://www.akadia.com/services/dotnet_delegates_and_events.html

Using JavaScript with ASP.Net GridView Control

am explaining how to make use JavaScript in the ASP.Net GridView control and make it more elegant by reducing postbacks.

Functions such as

1. Highlighting selected row

2. Check/Uncheck all records using single checkbox.

3. Highlight row on mouseover event.

The above three functions can be easily achieved using JavaScript thus avoiding postbacks.

To start with I have a GridView control with a header checkbox and checkbox for each individual record

To start with I have a GridView control with a header checkbox and checkbox for each individual record



































Above you will notice I am calling two JavaScript functions checkAll and Check_Click which I have explained later. Also I have attached a RowDataBound event to the GridView to add mouseover event





Highlight Row when checkbox is checked



The above function is invoked when you check / uncheck a checkbox in GridView row First part of the function highlights the row if the checkbox is checked else it changes the row to the original color if the checkbox is unchecked. The Second part loops through all the checkboxes to find out whether at least one checkbox is unchecked or not. If at least one checkbox is unchecked it will uncheck the Header checkbox else it will check it Check all checkboxes functionality The above function is executed when you click the Header check all checkbox When the Header checkbox is checked it highlights all the rows and checks the checkboxes in all rows. And when unchecked it restores back the original color of the row and unchecks the checkboxes. Note: The check all checkboxes checks all the checkboxes only for the current page of the GridView and not all. Highlight GridView row on mouseover event



The above JavaScript function accepts the reference of the GridView Row and the event which has triggered it.

Then based on the event type if event is mouseover it highlights the row by changing its color to orange else if the event is mouseout it changes the row’s color back to its original before the event occurred.

The above function is called on the mouseover and mouseout events of the GridView row. These events are attached to the GridView Row on the RowDataBound events refer the code below




C#

protected void RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow )

{

e.Row.Attributes.Add("onmouseover","MouseEvents(this, event)");

e.Row.Attributes.Add("onmouseout", "MouseEvents(this, event)");

}

}



VB.Net

Protected Sub RowDataBound(ByVal sender As Object,

ByVal e As GridViewRowEventArgs)

If e.Row.RowType = DataControlRowType.DataRow Then

e.Row.Attributes.Add("onmouseover", "MouseEvents(this, event)")

e.Row.Attributes.Add("onmouseout", "MouseEvents(this, event)")

End If

End Sub



You can try out the functionality discussed above using the sample GridView here


CustomerID City Country PostalCode
ALFKI Berlin Germany 12209
ANATR México D.F. Mexico 05021
ANTON México D.F. Mexico 05023
AROUT London UK WA1 1DP
BERGS Luleå Sweden S-958 22
BLAUS Mannheim Germany 68306
BLONP Strasbourg France 67000
BOLID Madrid Spain 28023
BONAP Marseille France 13008
BOTTM Tsawassen Canada T2F 8M4


The above JavaScript functions are tested in the following Browsers

1. Internet Explorer 7

2. Mozilla Firefox 3

3. Google Chrome





http://www.aspsnippets.com/post/2009/03/13/Using-JavaScript-with-ASPNet-GridView-Control.aspx

difference between gridview,data list and repeater control

Explanation:
In ASP .NET basically there are three kinds of the Data
Presentation Controls.


GridView (or DataGrid)
DataList
Repeater


When we talk about usage of one Data Presentation Controls
then many of us get confused about choosing one. When you
need to use one of the data Presentation Control then You
have to see what kind of behavior you need in your Data
Display.


Do you want to show Data in many Pages or in one page?
Do you have to Display more then one column in a Row ?

Do you want to have a Row repeating Possibility?

Will users be able to update, Insert and delete the Data?

We are going provide a list of different abilities of
Repeater Control, Datalist Control and GridView Control.



Features of a GridView
•Displays data as a table
•Control over
–Alternate item
–Header
–Footer
–Colors, font, borders, etc.
–Paging
•Updateable
•Item as row

Features of Repeater
•List format
•No default output
•More control
•More complexity
•Item as row
•Not updateable


Features of DataList
•Directional rendering
•Good for columns
•Item as cell
•Alternate item
•Updateable

Repeater :

It contains Header Template, Item template , alternate
Item template and footer template . it can't support
Selection, editing, sorting and paging. this is read only
and fast.


Datalist :

It contains Header Template, Item template , alternate
Item template , Edit itm template and footer template . it
can't support sorting and paging but support selection and
editing


DataGrid(or GridView) :

It contains Header Template, Item template , alternate Item
template , Edit itm template and footer template . it can
support selection, editing , sorting and paging . Mostly
every developer caught used this control .

Nesting the DropDownList to Gridview in ASP.NET 2.0(C#)

To nest the DropDownList control to GridView control is very helpful to show the data by selectable criteria. The DropDownList control can be easily nested to the GridView control. In this sample, each DropDownList is binded for different data. For instance, we can use GridView to show each category data in Northwind database, while we can use DropDownList to show all products under the selected category in each line. We will show you this tutorial by ASP.NET 2.0 and C#.

To nest the DropDownList control to GridView control is very helpful to show the data by selectable criteria. The DropDownList control can be easily nested to the GridView control. In this sample, each DropDownList is binded for different content. For instance, we can use GridView to show each category data in northwind database, and we can use DropDownList to show all products under the selected category in each line.

First, to connect to the sample database, you will need to import the System.Data.SqlClient namespace.

The front GridviewNestingDropdowlist.aspx page looks something like this:

GridviewNestingDropdowlist















The flow for the code behind page is as follows.
using System; using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class GridviewNestingDropdowlist : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
gridview1.DataSource = getdataset().Tables[0];
gridview1.DataBind();
}

private DataSet getdataset()
{
string connectionstring = "Data Source=localhost;Initial Catalog=northwind;User ID=sa;password=";
string query = "select p.categoryid,p.productid, p.productname,c.categoryid,c.categoryname from products p,categories c where p.categoryid=c.categoryid and c.categoryid<3";
SqlConnection myconnection = new SqlConnection(connectionstring);
SqlDataAdapter ad = new SqlDataAdapter(query, myconnection);
DataSet ds = new DataSet();
ad.Fill(ds);
return ds;
}

protected void gridview1_rowdatabound(object sender, GridViewRowEventArgs e)
{
DataTable mytable = new DataTable();
DataColumn productidcolumn = new DataColumn("productid");
DataColumn productnamecolumn = new DataColumn("productname");

mytable.Columns.Add(productidcolumn);
mytable.Columns.Add(productnamecolumn);

DataSet ds = new DataSet();
ds = getdataset();
int categoryid = 0;
string expression = string.Empty;

if (e.Row.RowType == DataControlRowType.DataRow)
{
categoryid = Int32.Parse(e.Row.Cells[0].Text);
expression = "categoryid = " + categoryid;
DropDownList ddl = (DropDownList)e.Row.FindControl("dropdownlist1");
DataRow[] rows = ds.Tables[0].Select(expression);

foreach (DataRow row in rows)
{
DataRow newrow = mytable.NewRow();
newrow["productid"] = row["productid"];
newrow["productname"] = row["productname"];
mytable.Rows.Add(newrow);
}
ddl.DataSource = mytable;
ddl.DataTextField = "productname";
ddl.DataValueField = "productid";
ddl.DataBind();
}
}
}