Wednesday, May 21, 2008

Working with postback of dropdown list inside Gridview

Many a times there are circumstances where by we need to use dropdown list inside a Gridview and also handle the index changed event of the dropdown list. The easy example of this kind of requirement would be when we nee to fill another dropdown list in the same row from the value selected in the first dropdown list. We all know that the dropdown list does not support command name property so you cannot handle the event in the row command event. A simple solution to the problem is to use the namingcontainer in the selectedindexchanged event and get the reference of the parent row view। After that we can do what we want from the row view Here is an example in the code -
protected void dropdownlist1_SelectedIndexChanged(object sender, EventArgs e) { // get reference to the rowGridViewRow gvr = (GridViewRow)(((Control)sender)।NamingContainer); // Get the reference of this DropDownlistDropDownList dropdownlist1 = (DropDownList) gvr.FindControl("dropdownlist1"); // Get the reference of other DropDownlist in the same row. DropDownList ddlParagraph = (DropDownList) gvr.FindControl("ddlParagraph");}

Tuesday, May 20, 2008

Windows Workflow Foundation ?



Windows Workflow Foundation is the programming model, engine and tools for quickly building workflow enabled applications on Windows. It consists of a .NET Framework version 3.0 (formerly WinFX) namespace, an in-process workflow engine, and designers for Visual Studio 2005. Windows Workflow Foundation is available for both client and server versions of Windows. Windows Workflow Foundation includes support for both system workflow and human workflow across a wide range of scenarios including: workflow within line of business applications, user interface page-flow, document-centric workflow, human workflow, composite workflow for service oriented applications, business rule driven workflow and workflow for systems management

Monday, May 19, 2008

C# 3.0 - Extension Methods

Developer code for assemblies. Compile it & publish it for client use. User of assembly may like to have some additional functionality in data types of the assembly. e.g int or Int32 do not have function to convert integer to complex number. ComplexNumber is the new data type defined by user.Now with C# 3.0 has provided with the concept of extension methods. Extension methods enable us to extend the functionality of data types already defined. No source code of the assembly is available to modify & recompile the assembly. Still one can extend the data types functionality.Inheritance also provides capability to extend the functionality but the extended functionality is available only for derived classes & not to the base class. e.g Consider I'd like to have a ToInt function in String class. If I use inheritance approach, I have to create new derived type. So I cannot use methods of derived type on my String objects.Extension methods are written in static class. The method should also a static method. First parameter of the method must be of type being extended. The first parameter must have this keyword before it.See the code below.
public static class ExtensionInt
{
public static Complex ToComplex(this int val)
{
Complex temp = new Complex();
temp।Real = val; return temp;
}
}
Complex is the type defined as follows:
public class Complex
{
public int Real;
public int Imag;
public override string ToString()
{
return (Real।ToString() + "+i" + Imag।ToString());
}
}
Use the method ToComplex for int or Int32.
static void Main(string[] args)
{
int i = 5; Console।WriteLine(i।ToComplex()।ToString());
}
Sealed classes can take advantage of extension methods. LINQ makes use of extension methods defined in Enumerable static class. The class extends functionality of objects implementing IEnumerable interface. To use the extension methods from Enumerable class refer the assembly System.Core.