Cool MSDN ASP.NET 2.0 GridView Control Article

Dino Esposito has published a great article on customizing the ASP.NET 2.0 GridView control, and shows how you can use it to look like the Hotmail inbox:

One thing he doesn't cover, but which is pretty darn cool, is that you can wrap it within an <atlas:updatepanel> and add some additional Atlas Control Toolbox controls to the page and have it be completely Ajax and cross-platform too (which is pretty sweet).

You can read the article here.

Hope this helps,

Scott

P.S. Scott Mitchell is writing 35+ step-by-step articles on databinding scenarios with ASP.NET 2.0 that is really going to rock.  He builds a DAL and then a Business Layer with the first two articles, and then spends the remainder showing off pretty much every common scenario you can think of against them (master/details, master/details/details, inline editing, sorting, paging, deleting, insertion, hierarchical, optimistic concurrency, scoped transactions, etc, etc).  I just reviewed the first 10 this past weekend and they are awesome.  We'll get them published on the web in the next few weeks.

Published Tuesday, April 18, 2006 8:46 PM by ScottGu
Filed under: ,

Comments

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, April 19, 2006 12:47 AM by Ryan
Just wanted to say... awesome work guys!! :)

Keep crankin'!!!

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, April 19, 2006 2:51 AM by Kris
Weren't you also busy creating such articles on your blog?

Grz, Kris.

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, April 19, 2006 3:06 AM by scottgu
Hi Kris,

I was -- and got two big ones done, but then got too busy at work (I unfortunately write blog posts simply as a side hobby <g>).

I ended up working with Scott Mitchell, though, to flesh out all the articles I had been hoping to-do. He has done a really, really awesome job with them so I think you'll like them a lot.

Hope this helps,

Scott

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, April 19, 2006 3:36 AM by Raj
Thanks Scott,

Its really helpful when you have some working samples to play with rather than just reading through the instructions (text) and do it yourself.

Regarding Scott Mitchell's Data tutorials...I'm so looking forward to it!

Thanks & best regards,

Raj

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, April 19, 2006 3:56 AM by mm
wow

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, April 19, 2006 5:08 AM by Jur0
This is all great but when you want to use GridView in some advanced way like dynamic tree Grids just don't fit. I'm not saying GridView is bad control. I believe it can be used in some good purposes but most of them are too simple.

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, April 19, 2006 8:26 AM by robertro
Het Scott, Will it cover how to embed ascx controls that require 2-way data-binding? we're looking at separating common functionality into ascx but need some guidance around the best data-binding techniques.

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, April 19, 2006 8:31 AM by Luciano Evaristo Guerche
Scott,

Would you mind posting Scott Mitchell articles' URLs?

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, April 19, 2006 8:51 AM by Nick.C
Just looking for this,Its really helpful.

Thank you sooo much

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, April 19, 2006 1:05 PM by cowgaR
Thanks to Scott & Scott =),

one question thought. Is it better to use GridView built in ASP.NET 2.0 callback feature or leave it turned off and use ATLAS framework instead?

thanks

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, April 19, 2006 3:54 PM by josanoop
thanks scott,

its really helpful and simple too.

josanoop

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, April 19, 2006 6:38 PM by DT
Hi Scott,
Do Scott Mitchell's articles cover custom DAL creation, or is it all using the designer and drag and drop? I would love to see a good article that uses a more general DAL approach.

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, April 19, 2006 7:12 PM by scottgu
Hi DT,

Scott's articles show how to build a business class layer that would work against pretty much any DAL. All of the databinding articles then go against this business layer.

This means you can swap in your own DAL implementation, and the articles are all still totally relevant.

Hope this helps,

Scott

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, April 19, 2006 7:33 PM by Varad
Oh Man,,Looking forward Scott M's article.

Hope thats going to be a gr8 tutorial for building a efeective Business Layer and DAL.

Thanks a lot for the info.

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, April 19, 2006 11:27 PM by scottgu
Hi Cowgar,

I would probabably recommend using an Atlas updatepanel for the GridView -- since that will give you the most flexibility.

Hope this helps,

Scott

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Thursday, April 20, 2006 2:45 PM by Rob Gaudet
Keep the great content coming! I am eating it up, (and using it too).

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Thursday, April 20, 2006 3:46 PM by Khuzema
Cant Wait, When they will be available. With inline editing it will be great if it shows how to do insert new records with Gridview.
(with reference to Scott Mitchell articles)
regards

Khuzema

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Sunday, April 30, 2006 12:18 PM by polaris
I found a error in the server control.
e.g
The selected rows only support 3 property:font-bold,backcolor and forecolor.It is not enough.
I updated this control and made it to support all sub-properties of SelectedRow.But only BorderStyle property does not run.
On the other hand , I added a new property which named CheckBoxText. The property sets or retrieves the checkbox Text of headerrow.
It is so good.
Thanks Dino and Scott.

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Monday, May 15, 2006 7:23 PM by Chris Love
Good Stuff, helped me with a task last week.

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, June 07, 2006 11:11 AM by ADurkin
This is really good stuff. One question on extending the GridView control, the new checkbox column isn't added to the Columns collection, any ideas on how to get it there?

# Strongly Typed DataBinding?

Monday, June 12, 2006 4:59 PM by Josh Gough
Looking forward to those DataBinding articles...

One thing I am wondering about right now is how to go about achieving Strongly Typed databinding within declarative templates.

About the closest thing I can come up with is hack that involves setting a Page level reference to the desired databound type:

http://www.dotnetjunkies.com/WebLog/joshuagough/archive/2006/06/08/140019.aspx

But, looking at the generated C# code, I think that it should be theoretically possible for the parser/compiler to check for something like Type="MyItemType" in the declaration of the control, and then use a generic Container, something like:


System.Web.UI.IDataItemContainer<MyItemType> Container;

In which case the .DataItem property of this class would be strong typed to MyItemType.

I'm migrating a large ASP 3.0 site to asp.net 2.0, and the amount of implementation details that go into the declarative markup is higher than the amount from asp 3.0, in which the UI designer could move around some columns within an include file but only have to worry about code like <%= .PropertyName %> when a With block was declared within code somewhere else in the parent page that includes the include.

With asp.net 2.0 you get intellisense support in the IDE in Markup view, which is fantastic, but it loses 100% of its value when you are stuck with Eval("PropertyNaem"). Oops, somebody misspelled PropertyName, but we won't find out until we browse to the page. Not even precompilation saves this.

Am I completely missing the boat? Is there a reason why strong-typing a templated control is physically imposible?

Thanks,
Josh









# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Monday, June 12, 2006 8:00 PM by ScottGu
Hi Josh,

If you want to program in a fully-qualified type-safe way inside <%# %> expressions you can.  The Eval() function is just a short-cut to allow you to do it latebound as well.

Alternatively you could write something like this:

<%# ((MyObject)(Container.DataItem)).MyProperty %>

Hope this helps,

Scott

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Tuesday, June 13, 2006 8:56 AM by Josh
Thanks Scott,

I am aware of that syntax, but it is a mess from a designer's perspective. It also involves extra casting on every bound item of the row. If you have 10 bound columns, you'd be performing 10 casts. I do prefer this syntax though:

(Container.DataItem as MyObject).MyProperty

since it saves a couple of keystrokes.

But the main problem is that it's just still too many keystrokes and far less elegant looking than the old ASP with the With block.

I don't fully understand the code below yet, but it just seems like if this code is autogenerated, then there should be a way to declaratively pass the type information into the parser/build process to automatically perform the casting/conversion step. The real beauty would be being able to just type ".<TAB>" in the IDE and get the strongly-typed intellisense.  Well...I can dream right? :-)

I tried to dig into the Page and Control builder providers with Reflector to understand how this works, but didn't get very far yet.


public void @__DataBind__control15(object sender, System.EventArgs e) {
           System.Web.UI.IDataItemContainer Container;
           System.Web.UI.DataBoundLiteralControl target;
         
           target = ((System.Web.UI.DataBoundLiteralControl)(sender));
         
         
           Container = ((System.Web.UI.IDataItemContainer)(target.BindingContainer));
         
         

           target.SetDataBoundString(0, System.Convert.ToString(Container.DataItem, System.Globalization.CultureInfo.CurrentCulture));
         
       }

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, June 21, 2006 2:04 AM by Sandeep Modi
I only thing that i don't know is that when you
extend control like in hotgrid then intellisense in not available inside <column> tag.
Any idea to fix that

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Thursday, June 22, 2006 1:15 AM by ScottGu
Hi Sandeep,

Can you provide more information about how you are declaring your columns?  You should have intellisense within them.

Thanks,

Scott

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, August 02, 2006 6:23 PM by Supreeth
Hi Scott, I am working on the grid view in asp.net. It's realy great. But to edit each line item, the user needs to click the edit button and then the line gets activated. What should I do if I want all the items to be activated based on my selection criteria?

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Tuesday, August 22, 2006 6:22 PM by Randy Brown
Scott, I'm trying to find those step-by-step articles that you said S. Mitchell was going to publish. Can't seem to find them anywhere and do not see a link to them here...did they ever get published? Thanks! Randy

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Tuesday, August 22, 2006 6:51 PM by ScottGu

Hi Randy,

Yep -- these tutorials have been posted (the first 27 of 40 of them) here: http://www.asp.net/learn/dataaccess/default.aspx?tabid=63

Thanks,

Scott

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Tuesday, August 22, 2006 7:01 PM by Randy Brown
Nevermind..I found them.

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Tuesday, September 26, 2006 10:58 AM by Gary
hi scott, did you try how to control the width of each column in this control? I found the width setting for each columns in this control did not work. gary

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, September 27, 2006 12:38 AM by ScottGu

Hi Gary,

Unfortunately it has been several months since I last tried this - so am not sure if I played with the width.  But you should be able to control it directly using the GridView control.

Hope this helps,

Scott

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, October 11, 2006 3:02 AM by Jos Janssen
Hello Gary, Same problem here. You have all these width properties for control-style/item-style/header/footer, but they just don't work. I see them back in HTML code, so the problem is in the browser???

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Friday, November 10, 2006 2:21 PM by Eric
Hi! I'm having problems when enabling SortingAndPagingCallbacks for the gridview. If it's enabled, and you change pages, the datakeys array is not refreshed.

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Wednesday, December 13, 2006 12:51 AM by davior

Hi Eric, The problem you are having is not releated to SortingAndPagingCallbacks. Its a problem with the GridView itself. Periodically it fails to maintain the viewstate of the DataKeys array... Very annoying!!

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Thursday, January 25, 2007 2:28 PM by Alper CELIK

Hi man...

Thanks for this crucial informations for me...it was a perfect match for my necessity

# Updating in gridview in Asp.net 2.0

Tuesday, January 30, 2007 9:28 AM by AMol Thengane

I want info about Updating in gridview in Asp.net 2.0.

# re: Cool MSDN ASP.NET 2.0 GridView Control Article

Thursday, March 15, 2007 5:02 PM by Steven

I am not sure if this new GridView extension useful.  If you click on the checkbox of the header and navigate to the second page, the checkbox in the header is still checked but none of the items is checked.  This is not even close to Hotmail feature. If the author want to have a sample, he need to make sure it works when it is published.