Monday, March 9, 2009

DropDownList inside Gridview

Hi All,

It is very common to have child controls inside the Gridview.Among them Drop down List is very common.Drop down list inside the gridview and handling their selected index changed event becomes inevitable.

We know that Drop Down list does not Support Command Name property so we cant handle the event in the Row Command event.

Here is the solution of it...which is used very very commonly...

protected void dropdownlist1_SelectedIndexChanged(object sender, EventArgs e) {

// get reference to the row

GridViewRow gvrow = (GridViewRow)(((Control)sender).NamingContainer);

// Get the reference of this DropDownlist

DropDownList ddl1= (DropDownList) gvrow.FindControl("dropdownlist1");

// Get the reference of other DropDownlist in the same row.

DropDownList ddl2= (DropDownList) gvrow.FindControl("dropdownlist2");

}


Thanks,

Nitin Sharma


Multiple Joins in LINQ



Hi All,
This Post will show how to implement multiple Joins in LINQ.



using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

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

{

DemoDataContext DC = new DemoDataContext();

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

Bind();

}

}

private void Bind()

{

// How to Apply Joins in LINQ

var items = from P in DC.Emps

join Ep in DC.EmpProducts on P.SINo equals Ep.SINo

join TT in DC.TextTables on P.SINo equals TT.SINo

select new

{

Name = P.Name,

Age = P.Age,

Country = P.Country,

State = P.State

};

GVInJoins.DataSource = items;

GVInJoins.DataBind();

}

}


On Debugging the Query we will find it like as........



{SELECT [t0].[Name], [t0].[Age], [t0].[Country], [t0].[State]
FROM [dbo].[Emp] AS [t0]
INNER JOIN [dbo].[EmpProduct] AS [t1] ON [t0].[SINo] = [t1].[SINo]
INNER JOIN [dbo].[TextTable] AS [t2] ON [t0].[SINo] = [t2].[SINo]
}




Now finally Bind the Output to the Gridview and its ready now...




Thanks to LINQ :)


Thanks,

Nitin Sharma

Add to Favorites/Bookmarks Using Javascript

Hi All,
Many a times while browsing we add our Pages to Favorites/Bookmarks.
This can be done by Javascript.
Below is the Javascript COde , which has benn simply called on HyperLink button.



function AddtoBookMarks()

{

if (document.all)

{

window.external.AddFavorite(location.href, document.title);

}

else if (window.sidebar)

{

window.sidebar.addPanel(document.title,location.href);

}

}

<asp:LinkButton ID="LnkFav" runat="server" OnClientClick="javascript:AddtoBookMarks();return false;">Add this Page to Favoritesasp:LinkButton>

Happy Coding..!

Nitin Sharma

Tuesday, March 3, 2009

Sachin Tendulkar at Madame Tussauds



CRICKETING LEGEND SACHIN TENDULKAR JOINS SPORTING GREATS AT MADAME TUSSAUDS LONDON

Record breaking cricketer, Sachin Tendulkar, will be the latest sporting great featured at the internationally renowned Madame Tussauds London when a new wax figure of the Mumbai-born batsman joins the A-list line up in April.
Tendulkar follows in the famous footsteps of Bollywood giants Amitabh Bachan, Aishwarya Rai, Shah Rukh Khan and Salman Khan and will join other cricket legends Brian Lara and Shane Warne to become the very first Indian sports personality to be portrayed.








Thanks,
Nitin Sharma

Disabling Right Click using JavaScript

Hey,
There are instances when we want to disable Right click on our Pages.The below script does the Magic.
Simply add the below snippet under Javascript Tag..


var message = "Sorry, Right Click is disabled.";

function click(e) {
if (document.all) {
if (event.button == 2) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown = click;

-------------------------------------------------------------------------------------------------
Also,


The below Javascript Disables right click(Mouse and Kyboard) ,Control Key.Save it as with anyName.js extension and Simply Give the path of .js file under the Javascript Tag
So below is the Script:



var isnn, isie
if (navigator.appName == 'Microsoft Internet Explorer') //check the browser
{ isie = true }

if (navigator.appName == 'Netscape')
{ isnn = true }

function right(e) //to trap right click button
{
if (isnn && (e.which == 3 || e.which == 2))
return false;
else if (isie && (event.button == 2 || event.button == 3)) {
alert("Sorry, you do not have permission to right click on this page.");
return false;
}
return true;
}

function key(k) {
if (isie) {
if (event.keyCode == 17 || event.keyCode == 18 || event.keyCode == 93) {
alert("Sorry, you do not have permission to press this key.")
return false;
}
}

if (isnn) {
alert("Sorry, you do not have permission to press this key.")
return false;
}
}

if (document.layers) window.captureEvents(Event.KEYPRESS);
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
document.onkeydown = key;
document.onmousedown = right;
document.onmouseup = right;
window.document.layers = right;








Cheers,
Nitin Sharma