Sunday, December 15, 2013

Saving changes is not permitted. The changes you have made require the following tables to be dropped and recreated...

Hi Friends,

If you see this error while you trying to save your table changes in sql server design mode,



 Follow the below steps to solve this issue.

Go to menu "Tools--> Options"
Select "Designers"
Uncheck the check box "Prevent saving changes that require table re-creation".

 
Thank you
 

Friday, December 9, 2011

XSLT - Numeric Checking

Hi Friends,

Here I would like to say about XSLT programming.
The example mentioned below is for finding the numeric values contained in an xml file.

For testing this example you need two files.

1. XML file its name should be "Numbers.xml"
2. XSL file its name should be "NumberCheck.xsl"

Copy these files to a folder and open the xml file in a browser.

"Numbers.xml"
---------------------
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="NumberCheck.xsl" ?>
<Numbers>
<Number>
<Value>11</Value>
</Number>
<Number>
<Value>12</Value>
</Number>
<Number>
<Value>DD</Value>
</Number>
<Number>
<Value>23</Value>
</Number>
<Number>
<Value>33</Value>
</Number>
<Number>
<Value>FF</Value>
</Number>
<Number>
<Value>VV</Value>
</Number>
</Numbers>

"NumberCheck.xsl"
---------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Numbers">
<TABLE>
<xsl:for-each select="Number">
<xsl:choose>
<xsl:when test='number(Value)'>
<TR>
<TD>
I am a numeric value : <xsl:value-of select="Value" />
</TD>
</TR>
</xsl:when>
<xsl:otherwise>
<TR>
<TD>
I am not a numeric value : <xsl:value-of select="Value" />
</TD>
</TR>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</TABLE>
</xsl:template>
</xsl:stylesheet>

In this example the xslt function <xsl:when test='number(Value)'> will help you to find the given value is a numeric or not

its out put will be like this

I am a numeric value : 11
I am a numeric value : 12
I am not a numeric value : DD
I am a numeric value : 23
I am a numeric value : 33
I am not a numeric value : FF
I am not a numeric value : VV

Wednesday, October 12, 2011

SQL Query for selecting database objects

1. SQL Query for selecting database objects

SELECT * FROM SYS.OBJECTS

2. SQL Query for selecting database Stored Procedurers

SELECT * FROM SYS.OBJECTS WHERE TYPE = 'P' ORDER BY NAME ASC

3. SQL Query for selecting database Tables

SELECT * FROM SYS.OBJECTS WHERE TYPE = 'U' ORDER BY NAME ASC

4.SQL Query for selecting database Functions

SELECT * FROM SYS.OBJECTS WHERE TYPE = 'FN' ORDER BY NAME ASC

5.SQL Query for selecting database Primary Keys

SELECT * FROM SYS.OBJECTS WHERE TYPE = 'PK' ORDER BY NAME ASC

Thursday, May 19, 2011

Play a video file in HTML

<object classid='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95' id='player' width='150'
height='150' standby='Please wait while the object is loaded...'>
<param name='url' value='D:\Experiments\clock.avi' />
<param name='src' value='D:\Experiments\clock.avi' />
<param name='AutoStart' value='false' />
<param name='Balance' value='0' /> //-100 is fully left, 100 is fully right.
<param name='CurrentPosition' value='0' /> //Position in seconds when starting.
<param name='showcontrols' value='true' /> //Show play/stop/pause controls.
<param name='enablecontextmenu' value='true' /> //Allow right-click.
<param name='fullscreen' value='true' /> //Start in full screen or not.
<param name='mute' value='false' />
<param name='PlayCount' value='1' /> //Number of times the content will play.
<param name='rate' value='1.0' /> //0.5=Slow, 1.0=Normal, 2.0=Fast
<param name='uimode' value='custom' /> // full, mini, custom, none, invisible
<param name='showdisplay' value='false' /> //Show or hide the name of the file.
<param name='volume' value='50' /> // 0=lowest, 100=highest
</object>

Tuesday, May 10, 2011

SQL Bulk Copy

SQL Bulk Copy is for moving data from one Table to another. This can be from a single server or between different servers (Source and destination are different servers).
SqlBulk copy class can be used to write data only to sql server tables. Any data source can be used for loading data as long as the data can be loaded to a Data Table or read with an IDataReader instance.
In The example mentioned below, I am using Oracle Table as source and Sql Server Table as destination. Also DataReader is using to fetch data from oracle.

SQL Bulk Copy Example

public void BulkCopyMethod()
{
string oracleConnectionString = "Data Source=SERVICENAME;User Id=USERNAME;Password=PASSWORD;";
string sqlConnectionString = "Data Source=DATASOURCE;Initial Catalog=DATABASENAME;Connect Timeout=0;User ID=USERNAME;Pwd=PASSWORD;";
string oracleSelectStatement = "SELECT EmployeeID,EmployeeName,EmployeeAge,EmployeePlace,EmployeePin,EmployeePhoneNum FROM EmployeeData";

using (OracleConnection oracleConn = new OracleConnection(oracleConnectionString))
{
oracleConn.Open();
OracleCommand employeeCommand = new OracleCommand(oracleSelectStatement, oracleConn);
OracleDataReader employeeReader = employeeCommand.ExecuteReader();

using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName = "dbo.tblEmployee";
bulkCopy.ColumnMappings.Add("EmployeeID", "Id");
bulkCopy.ColumnMappings.Add("EmployeeName", "Emp_Name");
bulkCopy.ColumnMappings.Add("EmployeeAge", "Emp_Age");
bulkCopy.ColumnMappings.Add("EmployeePlace", "Emp_Place");
bulkCopy.ColumnMappings.Add("EmployeePin", "Emp_Pin");
bulkCopy.ColumnMappings.Add("EmployeePhoneNum", "Emp_Phone");

try
{
bulkCopy.WriteToServer(employeeReader);
}
catch (Exception ex)
{
throw ex;
}
finally
{
bulkCopy.Close();
employeeReader.Close();
employeeCommand.Dispose();
oracleConn.Close();
}
}
}
}

For more info:- http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx

Monday, April 25, 2011

How to Serialize and DeSerialize a Generic List

private void button1_Click(object sender, EventArgs e)
{
List<Employee> emps = new List<Employee>();
emps.Add(new Employee("1", "Sabu"));
emps.Add(new Employee("2", "John"));
emps.Add(new Employee("3", "Tom"));
emps.Add(new Employee("4", "George"));
string serializedXmlString = XmlSerialize(emps);
List<Employee> deserializedEmps = XmlDeserialize(serializedXmlString);
}

//XmlSerialize method
public string XmlSerialize(List<Employee> emps)
{
System.Xml.Serialization.XmlSerializer xmlSer = new System.Xml.Serialization.XmlSerializer(emps.GetType());
StringWriter textWriter = new StringWriter();
xmlSer.Serialize(textWriter, emps);
xmlSer = null;
return textWriter.ToString();
}


//XmlDeserialize method
public List<Employee> XmlDeserialize(String data)
{
System.Xml.Serialization.XmlSerializer xmlSer = new System.Xml.Serialization.XmlSerializer(typeof(List<Employee>));
TextReader reader = new StringReader(data);
object obj = xmlSer.Deserialize(reader);
return (List<Employee>)obj;
}


//Employee Class with Serializable attribute

[Serializable]
public class Employee
{
public Employee()
{
ID = "";
Name = "";
}

public Employee(String id, String name)
{
ID = id;
Name = name;
}


public string ID { get; set; }
public string Name { get; set; }
}

SQL Table Reseeding

For Reseeding an Identity column use this statement.

DBCC CHECKIDENT (Employee, RESEED, 0)
Employee is the TABLE NAME. After the execution of this statement identity value will start from 1...

if you want to start from 11, execute statement like
DBCC CHECKIDENT (Employee, RESEED, 10)


DBCC means Database Console Commands.
this command statements are grouped in to several categories

  • Maintenance statements - Maintenance tasks on a database, index, or filegroup.
  • Miscellaneous statements - Miscellaneous tasks such as enabling row-level locking or removing a dynamic-link library (DLL) from memory.
  • Status statements - Status checks.
  • Validation statements - Validation operations on a database, table, index, catalog, filegroup, system tables, or allocation of database pages.

For more info
1. http://msdn.microsoft.com/en-us/library/aa258281(v=sql.80).aspx
2. http://msdn.microsoft.com/en-us/library/aa258817(v=sql.80).aspx

Monday, December 6, 2010

How to get DataKey in GridView's OnRowCommand event

/// <summary>
/// Handle grid Employee row command
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grdEmployee_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Details")
{
GridViewRow row = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
int index = row.RowIndex;
int EmployeeID = Convert.ToInt32(grdEmployee.DataKeys[index].Value);
}
}

Here “e.CommandSource” is the Clicked LinkButton and NamingContainer is its Parent Control. So that will be the GridViewRow. Here we can easily find the DataKey. Here in my Example EmployeeID is the DataKey

<asp:GridView ID="grdEmployee" runat="server"
EmptyDataText="No Employee Available."
Width="100%" AllowPaging="True"
PageSize="10" OnRowDeleting="grdEmployee_RowDeleting" OnPageIndexChanging="grdEmployee_PageIndexChanging"
DataKeyNames="EmployeeID"
OnRowCommand="grdEmployee_OnRowCommand">
<Columns>
<asp:BoundField HeaderText="Employee Code" DataField="EmployeeCode">
</asp:BoundField>
<asp:BoundField HeaderText="Employee Name" DataField="EmployeeName">
</asp:BoundField>
<asp:TemplateField HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:LinkButton ID="lbtnDelete" runat="server" CausesValidation="false" CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:LinkButton ID="lnkDetails" runat="server" CausesValidation="false" CommandName="Details" Text="View Details"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Friday, December 3, 2010

Difference between RadioButtonList and RadioButton

Difference between RadioButtonList and RadioButton
1. RadioButtonList

RadioButtonList is a single control with a list of RadioButtons.
This is derived from ListControl class. So this will work similar to other list controls like ListBox, DropDownList and CheckBoxList.
For giving a caption for buttons you can use the Text property. You cannot insert a text in between two buttons.
Using the “SelectedIndexChanged” event you will get the selected buttons value (“RadioButtonList1.SelectedValue”).
It is easy to bind this to a DataSource.
private void Bind()
{
RadioButtonList1.DataSource = dsEmployees;
RadioButtonList1.DataTextField = "EmployeeName";
RadioButtonList1.DataValueField = "EmployeeID";
RadioButtonList1.DataBind();
}
If you are using HTML
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
RepeatDirection="Horizontal"
onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem Text="Male" Value="1" ></asp:ListItem>
<asp:ListItem Text="Female" Value="2" ></asp:ListItem>
</asp:RadioButtonList>

2. RadioButton
“”RadioButton” is a single control, it is derived from “CheckBox” Class. You have to set the GroupName property to identify a group. Also the event handler for the event “CheckedChanged” will help us to do some job. Another one thing is you have to write separate handlers for each radio button.

For e.g.:
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="Gender"
AutoPostBack="true" oncheckedchanged="RadioButton1_CheckedChanged" Text="Male" />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="Gender"
AutoPostBack="true" oncheckedchanged="RadioButton2_CheckedChanged" Text="Female" />

Friday, October 29, 2010

Format Excel file using XSLT, XslCompiledTransform

See the sample code for creating an Excel file formatted with the help of XSLT file.
------------------------------------------------------------------------------------


private void button1_Click(object sender, EventArgs e)
{
ExportToExcel(GetDataSet(), "Employees.xslt", "c:\\Employees.xls");
}

Method to create a dataset for writing to excel
---------------------------------------------------------

private DataSet GetDataSet()
{
DataSet ds = new DataSet();
DataTable dtEmployees = new DataTable("Employees");
DataColumn colEmpID = new DataColumn("EmpID");
DataColumn colEmpName = new DataColumn("EmpName");
DataColumn colAge = new DataColumn("Age");
DataColumn colLocation = new DataColumn("Location");
DataColumn colDesignation = new DataColumn("Designation");
dtEmployees.Columns.AddRange(new DataColumn[] { colEmpID, colEmpName, colAge, colLocation, colDesignation });

DataRow dr = dtEmployees.NewRow();
dr[colEmpID] = "E001";
dr[colEmpName] = "George";
dr[colAge] = "45";
dr[colLocation] = "USA";
dr[colDesignation] = "PM";
dtEmployees.Rows.Add(dr);

dr = dtEmployees.NewRow();
dr[colEmpID] = "E002";
dr[colEmpName] = "James";
dr[colAge] = "30";
dr[colLocation] = "INDIA";
dr[colDesignation] = "TL";
dtEmployees.Rows.Add(dr);

dr = dtEmployees.NewRow();
dr[colEmpID] = "E002";
dr[colEmpName] = "Mary";
dr[colAge] = "35";
dr[colLocation] = "UK";
dr[colDesignation] = "Developer";
dtEmployees.Rows.Add(dr);

ds.Tables.Add(dtEmployees);
return ds;
}


Method to create a XSLT formatted excel file
---------------------------------------------------------

public bool ExportToExcel(DataSet ds, string xsltPath, string pathToSave)
{
try
{
XmlDataDocument xmlDoc = new XmlDataDocument();
xmlDoc.LoadXml(ds.GetXml());
XslCompiledTransform xsl = new XslCompiledTransform();
xsl.Load(xsltPath);
StreamWriter strWriter = new StreamWriter(pathToSave);
xsl.Transform(xmlDoc, null, strWriter);
strWriter.Flush();
return true;
}
catch (Exception ex)
{
throw ex;
}
}


Save the below mentioned XSLT in a file with name "Employees.xslt" in "C" drive to run the sample
---------------------------------------------------------

<xsl:stylesheet version="1.0"

xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:my-scripts"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:ms="urn:schemas-microsoft-com:xslt"
>
<xsl:template match="NewDataSet">
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<Styles>
<Style ss:ID="s21">
<Font ss:FontName="Arial" ss:Size="10" ss:Bold="1"/>
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>
</Style>
<Style ss:ID="s22">
<Font ss:FontName="MS Sans Serif" ss:Size="10"/>
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>
</Style>
<Style ss:ID="s25">
<Font ss:Color="Red" ss:FontName="MS Sans Serif" ss:Size="10"/>
<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>
</Style>
</Styles>
<Worksheet>
<xsl:attribute name="ss:Name">Employees List</xsl:attribute>
<Table>
<Column ss:Width="50"/>
<Column ss:Width="50"/>
<Column ss:Width="30"/>
<Column ss:Width="90"/>
<xsl:apply-templates select="NewDataSet"/>
<Row>
<Cell ss:StyleID="s21">
<Data ss:Type="String">Name</Data>
</Cell>
<Cell ss:StyleID="s21">
<Data ss:Type="String">Employee ID</Data>
</Cell>
<Cell ss:StyleID="s21">
<Data ss:Type="String">Age</Data>
</Cell>
<Cell ss:StyleID="s21">
<Data ss:Type="String">Location</Data>
</Cell>
<Cell ss:StyleID="s21">
<Data ss:Type="String">Designation</Data>
</Cell>
</Row>
<xsl:for-each select="Employees">
<Row>
<Cell ss:StyleID="s22">
<Data ss:Type="String">
<xsl:value-of select="EmpID"/>
</Data>
</Cell>
<Cell ss:StyleID="s22">
<Data ss:Type="String">
<xsl:value-of select="EmpName"/>
</Data>
</Cell>
<Cell ss:StyleID="s22">
<Data ss:Type="String">
<xsl:value-of select="Age"/>
</Data>
</Cell>
<Cell ss:StyleID="s22">
<Data ss:Type="String">
<xsl:value-of select="Location"/>
</Data>
</Cell>
<xsl:choose>
<xsl:when test="Designation='PM'">
<Cell ss:StyleID="s25">
<Data ss:Type="String">
<xsl:value-of select="Designation"/>
</Data>
</Cell>
</xsl:when>
<xsl:otherwise>
<Cell ss:StyleID="s22">
<Data ss:Type="String">
<xsl:value-of select="Designation"/>
</Data>
</Cell>
</xsl:otherwise>
</xsl:choose>
</Row>
</xsl:for-each>
</Table>
</Worksheet>
</Workbook>
</xsl:template>
</xsl:stylesheet>

Wednesday, October 13, 2010

Disable Save/Open Button in ASP.NET Download Dialog box

Code Behind

protected void Button1_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=sample.xls");
Response.Write("Hello World");
Response.End();
}

HTML Page

To disable Save button, write this meta tag
<head runat="server">
<meta name="DownloadOptions" content="nosave" />
</head>

To disable Open button, write this meta tag
<head runat="server">
<meta name="DownloadOptions" content="noopen" />
</head>

Friday, October 8, 2010

DataKey from a GridView RowCommand Event

Method to get DataKey from a GridView RowCommand Event

protected void grdEmployees_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
GridViewRow row = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
int index = row.RowIndex;
int employeeID = Convert.ToInt32(grdEmployees.DataKeys[index].Value);
}

}

For this eg: There should be GridView Control with a TemplateField and that should contain a Linkbutton with CommandName="Select"

SQL Query to Get SP and Text from DB

SELECT sysobjects.name, syscomments.text
FROM sysobjects JOIN syscomments ON
sysobjects.id = syscomments.id
WHERE xtype='P'

Write to Event Viewer

/// <summary>
/// Method to write Errors to Event viewer
/// </summary>
/// <param name="message">message</param>
static void WriteToEventViewer(string message)
{
string sSource = "Sample";
string sLog = "MyApplication";

if (!EventLog.SourceExists(sSource))
{
EventLog.CreateEventSource(sSource, sLog);
}
EventLog.WriteEntry(sSource, message,

EventLogEntryType.Error);
}

for more information refer this
http://msdn.microsoft.com/en-us/library/xzwc042w.aspx

Get Client Machine IP Address

/// <summary>
/// Method to get Client IP number
/// </summary>
/// <returns>IP Address</returns>
private string GetIPNumber()
{
return Request.UserHostAddress;
}

Friday, July 9, 2010

Dynamic SQL Query Building

Create SQL Table


CREATE TABLE [dbo].[Employee](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Address] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Phone] [varchar](15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Pin] [int] NULL,
CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

Insert Data in to Employee Table

INSERT INTO Employee([Name],[Address],[Phone],[Pin])VALUES('Sabu','Cochin','9876543210',682030)
INSERT INTO Employee([Name],[Address],[Phone],[Pin])VALUES('Arun','TVM','9876543210',789456)
INSERT INTO Employee([Name],[Address],[Phone],[Pin])VALUES('Rahul','BGLR','1472583690',456782)
INSERT INTO Employee([Name],[Address],[Phone],[Pin])VALUES('Ann','DELHI','1234566985',256314)
INSERT INTO Employee([Name],[Address],[Phone],[Pin])VALUES('Vipin','Cochin','5852369641',682020)

Procedure for searching for Employees
---------------------------------------------------


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
CREATE PROCEDURE pr_SearchEmployee
-- Add the parameters for the stored procedure here
@EmployeeName varchar(20)
,@EmployeeAddress nvarchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @searchQuery varchar(300)
SET @searchQuery = 'SELECT [ID]
,[Name]
,[Address]
,[Phone]
,[Pin]
FROM Employee WHERE '
IF len(@EmployeeName) > 0
BEGIN
SET @searchQuery = @searchQuery + '[Name] LIKE ' + char(39) + '%' + @EmployeeName + '%' + char(39)
END
ELSE IF len(@EmployeeAddress) > 0
BEGIN
SET @searchQuery = @searchQuery + '[Address] LIKE ' + char(39) + '%' + @EmployeeAddress + '%' + char(39)
END
EXEC (@searchQuery)
END
---------------------------------------------------------------------------
Execute Procedure
EXEC pr_SearchEmployee '','Cochin'

Wednesday, June 2, 2010

Embed Windows Mediaplayer in a Web Page

<HTML>
<HEAD>
<TITLE>Embed Media player</TITLE>
</HEAD>
<BODY>
<OBJECT id="media1" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject" width="300" height="300">
<PARAM NAME="URL" VALUE="intro.wmv">
<PARAM NAME="ENABLED" VALUE="True">
<PARAM NAME="AUTOSTART" VALUE="False">
<PARAM name="PLAYCOUNT" value="2">
<PARAM name="VOLUME" value="50">
<PARAM NAME="MUTE" VALUE="False">
<PARAM NAME="FULLSCREEN" VALUE="FALSE">
<PARAM name="UIMODE" value="full">
</OBJECT>
</BODY>
</HTML>

Monday, February 22, 2010

Anonymous Methods Vs Named Methods

create a console application in c#.net and copy this

namespace ConsoleApplication1
{
class Program
{
//Declaring a delegate
delegate void Display(String text);

static void Main(string[] args)
{
//Anonymous method
Display d = delegate(String s)
{
Console.WriteLine(s + "Anonymous method");
};

//Calling anonymous method
d("I am calling ");

d = new Display(Program.Foo);

//Calling named method
d("I am calling ");

Console.ReadLine();
}

/// Named method
public static void Foo(String text)
{
Console.WriteLine(text + "Named Method.");
}
}
}

You cannot use a "ref" or "out" variable inside an anonymous method.
If you are using a variable that is declared outside the anonymous method is called "outer" or "captured" variables of the anonymous method.

eg:-
string outside = "I am captured";
//Anonymous method
Display d = delegate(String s)
{
Console.WriteLine(s + "Anonymous method " + outside);
};

Sunday, February 21, 2010

Conditional Loop In XSLT

XML
--------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="test.xslt" ?>
<Root>
<Title>Looping function example</Title>
<Limit>10</Limit>
</Root>


XSLT
----------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/">

<html>
<head>
<title> <xsl:value-of select="Root/Title" /> </title>
</head>
<body>
<!--CALLING FUNCTION -->

<h3><xsl:value-of select="Root/Title" /></h3>
<xsl:call-template name="LoopingFunc">
<xsl:with-param name="limit" select="Root/Limit" />
</xsl:call-template>
</body>
</html>
</xsl:template>
<!--LOOPING FUNCTION -->

<xsl:template name="LoopingFunc">
<xsl:param name="limit"/>
<xsl:if test="$limit > 0">
<h5>
<xsl:value-of select="$limit"/>
</h5>
<xsl:call-template name="LoopingFunc">
<xsl:with-param name="limit" select="$limit - 1" />
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>


Out put
----------------
Looping function example
10
9
8
7
6
5
4
3
2
1

Thursday, February 18, 2010

Enable and Disable a Control by Binding to another Control


You can Set the Enable Property of a control by binding that control to another control.

How to Achieve this?

See this code snippet.This is a Windows Application Project with C# language.
To test this code you should have a TextBox named "txtName" and a CheckBox named "chk".

In the form load event write this

txtName.DataBindings.Add("Enabled", chk, "Checked");
Execute code and check and uncheck CheckBox. So that you can find the TextBox's property changing.