ASP.NET Dynamic Data Preview #7: How Do I Use a DynamicControl in ListView and DetailsView Controls?
This video compares the same application written twice, once with Dynamic Data and once without. In the process, you add DynamicControl objects to ListView and DetailsView controls.
http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.dynamiccontrol.aspx
http://www.bestechvideos.com/2008/06/02/asp-net-dynamic-data-how-do-i-use-a-dynamiccontrol-in-listview-and-detailsview-controls
Sorting Generic List
//Sorting List<> case Item is ListItem //============================================== List<ListItem> tempList = new List<ListItem>(); tempList.Insert(0, new ListItem("------------- Vehicle Reports 8")); tempList.Insert(0, new ListItem("------------- Vehicle Reports 2")); tempList.Insert(0, new ListItem("------------- Vehicle Reports 4")); // sort asc tempList.Sort(delegate(ListItem p1, ListItem p2) { return p1.Text.CompareTo(p2.Text); }); // sort desc tempList.Sort(delegate(ListItem p1, ListItem p2) { return p2.Text.CompareTo(p1.Text); }); //Sorting List<> case Item is Object Class //=============================================== //Apply to sorting in GridView //=============================================== SortData(e.SortExpression, NewSortDirection, ref listMsgTicker); //=============================================== #region method for sorting private void SortData(string _expression, SortDirection _direction, ref List<MsgTicker> data) { //sort asc == if (_direction == SortDirection.Ascending) data.Sort(delegate(MsgTicker a, MsgTicker b) { switch (_expression) { case "MsgHeader": return a.MsgHeader.CompareTo(b.MsgHeader); case "CreatedDate": return a.CreatedDate.CompareTo(b.CreatedDate); case "ModifiedDate": return a.ModifiedDate.CompareTo(b.ModifiedDate); default: throw new NotImplementedException("Type of property not implemented yet"); } }); //sort desc == if (_direction == SortDirection.Descending) data.Sort(delegate(MsgTicker a, MsgTicker b) { switch (_expression) { case "MsgHeader": return b.MsgHeader.CompareTo(a.MsgHeader); case "CreatedDate": return b.CreatedDate.CompareTo(a.CreatedDate); case "ModifiedDate": return b.ModifiedDate.CompareTo(a.ModifiedDate); default: throw new NotImplementedException("Type of property not implemented yet"); } }); //return data; } #endregion ref: http://dotnetslackers.com/Community/blogs/simoneb/archive/2007/06/20/How-to-sort-a-generic-List_3C00_T_3E00_.aspx
ThaiBuddhistCalendar and DateTime Convertion
//date time utc DateTime _utc = DateTime.UtcNow; // utc --> thai ThaiBuddhistCalendar tbc = new ThaiBuddhistCalendar(); int thaiDay = tbc.GetDayOfMonth(_utc); int thaiMonth = tbc.GetMonth(_utc); int thaiYearr = tbc.GetYear(_utc); string thaiDaate = thaiDay.ToString("00") + "/" + thaiMonth.ToString("00") + "/" + thaiYearr.ToString("0000"); // thai --> utc DateTime _do, _UtcTime; DateTime.TryParseExact(thaiDaate, "dd/MM/yyyy", new CultureInfo("th-TH"), DateTimeStyles.None, out _do); _UtcTime = _do.ToUniversalTime(); ref: http://msdn.microsoft.com/en-us/library/system.globalization.thaibuddhistcalendar.getera.aspx
Tips to optimize design-time build performance for Web Sites in Visual Studio
There have been a number of posts with tips to improve build performance within Visual Studio 2005. I’ve consolidate these posts and other tips into a single post of techniques for common problems.
ref: http://weblogs.asp.net/bradleyb/archive/2005/12/06/432441.aspx
LINQ to SQL Debug Visualizer
Probably the biggest programming model improvement being made in .NET 3.5 is the work being done to make querying data a first class programming concept. We call this overall querying programming model “LINQ”, which stands for .NET Language Integrated Query. Developers can use LINQ with any data source, and built-in libraries are included with .NET 3.5 that enable LINQ support against Objects, XML, and Databases.
Earlier this summer I started writing a multi-part blog series that discusses the built-in LINQ to SQL provider in .NET 3.5. LINQ to SQL is an ORM (object relational mapping) implementation that allows you to model a relational database using .NET classes. You can then query the database using LINQ, as well as update/insert/delete data from it. LINQ to SQL fully supports transactions, views, and stored procedures. It also provides an easy way to integrate data validation and business logic rules into your data model.
You can learn more about LINQ to SQL by reading my posts below (more will be coming soon):
- Part 1: Introduction to LINQ to SQL
- Part 2: Defining our Data Model Classes
- Part 3: Querying our Database
- Part 4: Updating our Database
- Part 5: Binding UI using the ASP:LinqDataSource Control
Ref: http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx
Using LINQ with ASP.NET (Part 1)
One of the new things I’m super excited about right now is the LINQ family of technologies that are starting to come out (LINQ, DLINQ, XLINQ and others soon).
LINQ will be fully integrated with the next release of Visual Studio (code-name: Orcas) and it will include some very cool framework and tool support (including full intellisense and designer support). Last week the LINQ team released the May CTP drop of LINQ that you can download from here. What is cool about this CTP is that it works with VS 2005, and allows you to start learning more about it immediately. It incorporates a bunch of customer feedback (for example: support for stored procedures in DLINQ), and also includes a built-in ASP.NET Web-Site Project to enable you to leverage it with ASP.NET apps (note: you can also use LINQ with the new VS 2005 Web Application Project option as well).
I’m going to put together a few blog postings over the next few weeks that show off ways to use LINQ/DLINQ/XLINQ within ASP.NET projects. This first walkthrough below will help you get started and introduce some of the important LINQ concepts. You can follow-along by downloading the May CTP LINQ preview above and typing in the code below (I list all of it below), or you can download and run the complete .zip file of my samples here (note: you still need to install the LINQ May CTP drop for the .zip file of samples to work).
Note: LINQ, DLINQ and XLINQ will be fully supported in both C# and VB. I am using C# for the example belows.
ref: http://weblogs.asp.net/scottgu/archive/2006/05/14/446412.aspx
Working with LINQ Using Visual Studio 2005
LINQ is the general-purpose standard query operator that allows traversal, filter and projection operations to be expressed in a direct yet declarative way in any .NET programming language. The extensibility of the LINQ query language provides implementations that work over both XML and SQL data. The query operator over XML is called XLINQ and the one over SQL is called DLINQ. XLINQ is an efficient and in-memory XML facility to provide XPath/XQuery functionality. DLINQ operator is for the integration of SQL based schema definitions into the CLR type System.
LINQ will be fully integrated with the next release of the Visual Studio, which is named as Orcas now. The best thing is that the LINQ can also be installed in Visual Studio 2005. The May 2006 CTP release of LINQ is available and can be downloaded from this link. Let us see how to create a new web site that uses LINQ features.
Solve Error : ASP.NET runtime error: Could not load file or assembly ‘AjaxControlToolkit, Version=1.0.10920.32880
Add following XML to the eScrum web.conifg file after the </configSections> close tag. Afterward, update the newVersion attribute to the version of the control toolkit that you are using.
<runtime>
<assemblyBinding xmlns=”urn
chemas-microsoft-com:asm.v1″>
<dependentAssembly>
<assemblyIdentity name=”AjaxControlToolkit”
publicKeyToken=”28f01b0e84b6d53e”
culture=”neutral”/>
<bindingRedirect oldVersion=”1.0.10301.0″ newVersion=”1.0.xxxxx.0″/>
</dependentAssembly>
</assemblyBinding>
</runtime>
ref: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1913881&SiteID=1
Comparing two objects ( == instead of .equals)
Here’s the correct way to compare two strings.
String abc = “abc”; String def = “def”;
// Bad way
if ( (abc + def) == “abcdef” )
{
……
}
// Good way
if ( (abc + def).equals(“abcdef”) )
{
…..
}
VS2005 Take (Keyboard) Shortcuts
Using keyboard shortcuts is the best way to get things done faster in Visual Studio (and most other computer applications for that matter).
Below are my favorite Visual Studio keyboard shortcuts (I am leaving out the really obvious ones like F5).
- CTRL+ALT+L: View Solution Explorer. I use Auto Hide for all of my tool windows to maximize screen real estate. Whenever I need to open the Solution Explorer, it’s just a shortcut away. Related shortcuts: CTRL+ALT+X (Toolbox), F4 (Properties), CTRL+ALT+O (Output), CTRL+\, E (Error List), CTRL+\, T (Task List).
- F12: Go to definition of a variable, object, or function.
- SHIFT+F12: Find all references of a function or variable.
- F7: Toggle between Designer and Source views.
- CTRL+PgDn: Toggle between Design and Source View in HTML editor.
- F10: Debug – step over. Related debugging shortcuts: F5 (debug – start), F11 (debug – step into), SHIFT-F11 (debug – step out), CTRL-F10 (debug – run to cursor). F9 (toggle breakpoint).
- CTRL+D or CTRL+/: Find combo (see section on Find Combo below).
- CTRL+M, O: Collapse to Definitions. This is usually the first thing I do when opening up a new class.
- CTRL+K, CTRL+C: Comment block. CTRL+K, CTRL-U (uncomment selected block).
- CTRL+-: Go back to the previous location in the navigation history.
- ALT+B, B: Build Solution. Related shortcuts: ALT+B, U (build selected Project), ALT+B, R (rebuild Solution).
- CTRL+ALT+Down Arrow: Show dropdown of currently open files. Type the first few letters of the file you want to select.
- CTRL+K, CTRL+D: Format code.
- CTRL+L: Delete entire line.
- CTRL+G: Go to line number. This is useful when you are looking at an exception stack trace and want to go to the offending line number.
- SHIFT+ALT+Enter: Toggle full screen mode. This is especially useful if you have a small monitor. Since I upgraded to dual 17″ monitors, I no longer needed to use full screen mode.
- CTRL+K, X: Insert “surrounds with” code snippet. See Snippets tip below.
- CTRL+B, T: Toggle bookmark. Related: CTRL+B, N (next bookmark), CTRL+B, P (prev bookmark).
The complete list of default shortcuts is available from VS 2005 Documentation. You can also download/print reference posters from Microsoft: C# Keyboard Reference Poster, VB.NET Keyboard Reference Poster.