.NET Software Development Stack: ASP.NET, WPF, WinForms, ADO.NET, Entity Framework, SQL, Design Patterns
Friday, July 4, 2008
What's the difference between Bind and Eval
Data-binding expressions are resolved when the DataBind method of a control or of the Page class is called. For controls such as the GridView, DetailsView, and FormView controls, data-binding expressions are resolved automatically during the control's PreRender event and you are not required to call the DataBind method explicitly.
Using the Eval Method
The Eval method evaluates late-bound data expressions in the templates of data-bound controls such as the GridView, DetailsView, and FormView controls. At run time, the Eval method calls the Eval method of the DataBinder object, referencing the current data item of the naming container. The naming container is generally the smallest part of the data-bound control that contains a whole record, such as a row in a GridView control. You can therefore use the Eval method only for binding inside templates of a data-bound control.
The Eval method takes the name of a data field and returns a string containing the value of that field from the current record in the data source. You can supply an optional second parameter to specify a format for the returned string. The string format parameter uses the syntax defined for the Format method of the String class.
Using the Bind Method
The Bind method has some similarities to the Eval method, but there are significant differences. Although you can retrieve the values of data-bound fields with the Bind method, as you can with the Eval method, the Bind method is also used when data can be modified.
In ASP.NET, data-bound controls such as the GridView, DetailsView, and FormView controls can automatically use the update, delete, and insert operations of a data source control. For example, if you have defined SQL Select, Insert, Delete, and Update statements for your data source control, using Bind in a GridView, DetailsView, or FormView control template enables the control to extract values from child controls in the template and pass them to the data source control. The data source control in turn performs the appropriate command for the database. For this reason, the Bind function is used inside the EditItemTemplate or InsertItemTemplate of a data-bound control.
The Bind method is typically used with input controls such as the TextBox control rendered by a GridView row in edit mode. When the data-bound control creates these input controls as part of its own rendering, it can extract the input values.
The Bind method takes the name of a data field to associate with the bound property.
Wednesday, July 2, 2008
More information about ASP.NET Page life-cycle and common events
I’ve found wonderful document about ASP.NET Page lifecycle events on http://john-sheehan.com/blog. Little information about general page Life-cycle stages and events:
The whole document can be found here: http://john-sheehan.com/blog/wp-content/uploads/aspnet-life-cycles-events.pdf . There is also information about Data Binding Events for Data-Bound Controls and Common Life-cycle Events.
Enjoy :)
Monday, June 30, 2008
Tooltip in ASP.NET GridView headers
I was searching for the way show Tooltips for headers of ASP.NET GridView control without using javascript or using unnecessary overhead in code. And I found the way how to do it. When you define columns or your GridView you should use TemplateField instead of BoundField cause it's customizable. In TemplateField you can define HeaderTemplate and put there Label control with needed Tooltip. Here is the code:
<asp:GridView ID="GridView" DataSourceID="ObjectDataSource1" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField SortExpression="ShareCount">
<HeaderTemplate>
<asp:Label runat="server" Text="Nr. of Stocks" ToolTip="Total number of stocks on the market"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("ShareCount") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
.NET Format Strings
Here is the sample from it.

Full document can be downloaded from John Sheehan blog :
http://john-sheehan.com/blog/wp-content/uploads/msnet-formatting-strings.pdf
Sunday, June 29, 2008
ASP.NET data binding essentials
<%# %> Syntax
ASP.NET introduces a new declarative syntax, <%# %>. This syntax is the basis for using data binding in an .aspx page. All data binding expressions must be contained within these characters. The following list includes examples of simple data binding from multiple sources:
• Simple property (syntax for a customer):
<%# custID %>
• Collection (syntax for an order):
<asp:listbox id="List1" datasource="'<%#">' runat="server">
• Expression (syntax for a contact):
<%# ( customer.First Name + " " + customer.LastName ) %>
• Method result (syntax for the outstanding balance):
<%# GetBalance(custID) %>
In the preceding examples, the inline <%# %> tags indicate where the information from a specific data source is to be placed in the .aspx page. The following data binding example uses a TextBox Web server control: <asp:textbox id="txt" text=="<%# custID %>" runat=server />
For more information about data binding syntax, see the following .NET Framework Software Development Kit (SDK) documentation:
Data Binding Expression Syntax
http://msdn2.microsoft.com/en-us/library/bda9bbfx(vs.71).aspx
Friday, June 27, 2008
WPF Beginners Guide
WPF: A Beginner's Guide - Part 1 of n
WPF: A Beginner's Guide - Part 2 of n
WPF: A Beginner's Guide - Part 3 of n
WPF: A Beginner's Guide - Part 4 of n
WPF: A Beginner's Guide - Part 5 of n
WPF: A Beginner's Guide - Part 6 of n
I hope this will greatly help many of you and you'll get main concepts and basics of this wonderful technology. Here is his blog: Sacha Barber blog
VS 2005 Error 1: "Could not load type..."
You can receive this error "Could not load type" error message in your ASP.NET Application, when you browse to .aspx page by using Visual C# .NET or running from local IIS.
SYMPTOMS
When you browse to an .aspx page, you may receive one of the following error messages:
Could not load type 'Namespace.Global'.
-or-
Could not load type 'Namespace.PageName'.
CAUSE
These errors occur if the .aspx page or the Global.asax page contains a reference to a code-behind module and if the application has not been built.
RESOLUTION
Use one of the following methods to build the application:
• Use the C# command line compiler (CSC.exe) to run the following command:
csc /t:library /r:System.web.dll /out:mydll.dll myfile.cs
• In Microsoft Visual Studio .NET, click Build on the Build menu.
NOTE: Microsoft Visual Basic .NET background compiles the project as soon as it is created. Because Visual C# .NET projects only background parse, you must explicitly build the application.
Steps to Reproduce the Behavior
1. Start Visual Studio .NET.
2. On the File menu, point to New, and then click Project.
3. Click Visual C# Projects under Project Types, and then click ASP.NET Web Application under Templates.
4. Right-click WebForm1.aspx, and then click View in Browser.
Materials are taken from http://support.microsoft.com/kb/306155