Wednesday, December 28, 2011

How to get Dropdown Selected value using javascript in ASP.NET?

2 comments Posted by Rahul Kharde at 9:56 PM
I have dropdownlist box, when I change the value in the dropdownlist box javascript function get fired. And it will shows the selected value in the popup box.

HTML

So first add an aspx page into your project & paste the below code for asp:dropdownlist under the form div section:

<asp:DropDownList ID="DropDownList1" runat="server" OnChange="javascript:GetDropDownValue()">

<asp:ListItem Value="1">C#</asp:ListItem>

<asp:ListItem Value="2">ASP</asp:ListItem>

<asp:ListItem Value="3">WPF</asp:ListItem>

<asp:ListItem Value="4">WCF</asp:ListItem>

<asp:ListItem Value="5">C++</asp:ListItem>

asp:DropDownList>

Javascript

Add javascript function in head tag

function GetDropDownValue()

{

var IndexValue = document.getElementById('<%=DropDownList1.ClientID %>').selectedIndex;

var SelectedVal = document.getElementById('<%=DropDownList1.ClientID %>').options[IndexValue].text;

alert(SelectedVal);

}

Output

Download

Download Code Here….

Read More »

Wednesday, December 21, 2011

Create First WPF Browser Application

0 comments Posted by Rahul Kharde at 3:09 AM
Are you new to WPF? This article is help to understand and run your Browser application first time. We create a simple WPF Browser Application

In Microsoft Visual Studio Open menu File -> Project

Select “WPF Browser Application” Click “OK” Button

Here we have one textbox and Button

Page1.xaml

<Page x:Class="FirstExample.Page1"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="Page1">

<Grid>

<StackPanel>

<TextBox Margin="103,30,102,35" Name="txtName" Width="100">TextBox>

<Button Margin="103,50,112,145" Name="button1" Click="button1_Click" Width="100">Click Me..Button>

</StackPanel>

</Grid>

</Page>

Page1.xaml.cs

namespace FirstExample

{

public partial class Page1 : Page

{

public Page1()

{

InitializeComponent();

}

private void button1_Click(object sender, RoutedEventArgs e)

{

MessageBox.Show("Hello "+txtName.Text);

}

}

}

Output

Download

Download code here..

Read More »

Tuesday, December 20, 2011

Difference between Destructor, dispose and finalize method?

1 comments Posted by Rahul Kharde at 2:50 AM

Destructor

They are special methods that contains clean up code for the object. You can’t call them explicitly in your code as they are called implicitly by GC (Garbage Collector). In C# they have same name as the class name preceded by the "~" sign. Like-

class MyClass
{
    public MyClass()
    {
    }
    ~MyClass()
    {
    }
}


Dispose

These are just like any other methods in the class and can be called explicitly but they have a special purpose of cleaning up the object. In the dispose method we write clean up code for the object. It is important that we freed up all the unmanaged resources in the dispose method like database connection, files etc.
The class implementing dispose method should implement IDisposable which is inherited by interface and it contains GC.SuppressFinalize method for the object it is disposing if the class has destructor because it has already done the work to clean up the object, then it is not necessary for the garbage collector to call the object's Finalize method.
  • Dispose() is called by the user
  • Same purpose as finalize, to free unmanaged resources. However, implement this when you are writing a custom class that will be used by other users.
  • Overriding Dispose () provides a way for the user code to free the unmanaged objects in your custom class.
  • Dispose method can be invoked only by the classes that IDisposable interface.


Finalize

Finalize () is called by Garbage Collector implicitly to free unmanaged resources. The garbage collector calls this method at some point after there are no longer valid references to the object. There are some resources like windows handles, database connections which cannot be collected by the garbage collector. Therefore the programmer needs to call Dispose() method of IDisposable interface.
  • Implement it when you have unmanaged resources in your code, and want to make sure that these resources are freed when the Garbage collection happens.
  • Finalizers should release unmanaged resources only.
  • Finalizers should always be protected, not public or private so that the method cannot be called from the application's code directly and at the same time, it can make a call to the base.Finalize method
class MyClass : IDisposable
{
    private bool IsDisposed = false;
    public void Dispose()
    {
        Dispose(true);
        GC.SupressFinalize(this);
    }
    protected void Dispose(bool Diposing)
    {
        if (!IsDisposed)
        {
            if (Disposing)
            {
                //Clean Up managed resources
            }
            //Clean up unmanaged resources
        }
        IsDisposed = true;
    }
    ~MyClass()
    {
        Dispose(false);
    }
}

Read More »

Sunday, December 18, 2011

Cross Join in SQL-Server

0 comments Posted by Rahul Kharde at 10:33 PM

Cross Joins produce results that consist of every combination of rows from two or more tables. That means if table A has n rows and table B has m rows, a CROSS JOIN will result in n X m rows.
There is no Where Condition used in cross join

SQL CROSS JOIN syntax:

SELECT * FROM [TABLE 1] CROSS JOIN [TABLE 2]
OR
SELECT * FROM [TABLE 1], [TABLE 2]


Example

CREATE TABLE [dbo].[Student]
(
[StudID] [int] IDENTITY(1,1) NOT NULL,
[StudName] [varchar](50)
)
CREATE TABLE [dbo].[Division]
(
[DivisionID] [int] IDENTITY(1,1) NOT NULL,
[DivisionName] [varchar](50)
)
INSERT INTO Student(StudName) VALUES('ABC')
INSERT INTO Student(StudName) VALUES('XYZ')
INSERT INTO Division(DivisionName) VALUES('Division 1')
INSERT INTO Division(DivisionName) VALUES('Division 2')
INSERT INTO Division(DivisionName) VALUES('Division 3')


SELECT * FROM Student
CROSS JOIN Division


OUTPUT
We have two table Student and Division corresponding 2 and 3 rows in table cross join return

2 X 3 = 6 Rows

Read More »

Wednesday, December 14, 2011

Difference between Clustered and Non-Clustered Index in SQL-SERVER

0 comments Posted by Rahul Kharde at 12:26 AM

There are clustered and non-clustered indexes. A clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore table can have only one clustered index. The leaf nodes of a clustered index contain the data pages.

A non-clustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf node of a non clustered index does not consist of the data pages. Instead, the leaf nodes contain index rows.

Using DML (Data Manipulation Language) statement on cluster index column have performance issues since it has to update the index each and every time a DML gets executed.

Clustered Index
Non-Clustered Index
Only one per table
Can be used many times per table
There can be only 1 Clustered index in a table. This is usually made on the primary key. Whereas non-clustered index can be up to 249
Clustered is physical sorted index
A non clustered index is a special type of index in which the logical order of the index
Data retrieval faster
Insert and update statements faster
Leaf nodes in B-Tree structure contains actual rows.
Leaf pages in B-Tree structure contains pointers to actual rows.

Example

CREATE TABLE Student
(
StudID INT PRIMARY KEY CLUSTERED,
FirstName VARCHAR(100),
LastName VARCHAR(100),
Address VARCHAR(100) UNIQUE NONCLUSTERED
)
GO
CREATE NONCLUSTERED INDEX Student_nonclust ON Student(FirstName)
GO
After creating the CLUSTERED and NONCLUSTERED index it will show like

Read More »
 

Popular Posts

Recent Comments

© 2011. All Rights Reserved | Help to understand .Net | Template by Blogger Widgets

Home | About | Top