Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 24th, 2012, 04:34 PM
Authorized User
Points: 224, Level: 4
Points: 224, Level: 4 Points: 224, Level: 4 Points: 224, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Posts: 41
Thanks: 3
Thanked 4 Times in 3 Posts
Default Listview, general question

Hi,

I am wondering on the flexibility of using a listview control. E.g., Can I add code to check a value within a list item, and then decide whether to change the background color of the list item box? Would this code go into an Item event? I would have guessed the ItemCreating event except that this event doesn't exist. Maybe this custom code can go in the ItemCreated event?

I was using a user control prior because it gave me great ease and flexibility on layout. And I could simply put code into the code behind. However, since everyone is telling me that I should use a listview control, I would like to know if it is just as easy to custom code the layout design with a listview.

Thanks,

- nano
Reply With Quote
  #2 (permalink)  
Old June 25th, 2012, 03:03 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Well, I suggested a ListView because it seems a lot easier than generating user controls on the fly and manage your own state. That's not to say that you have to use the ListView and that a UC is a bad practice; it all depends on your design and what you're trying to accomplish.

That said, ItemCreated is indeed a good place. Here's a quick example:

Code:
protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
{
  Label description = e.Item.FindControl("DescriptionLabel") as Label;
  Picture picture = e.Item.DataItem as Picture;
  if (picture != null)
  {
    if (picture.Id  > 5)
    {
      description.CssClass = "Alert";
    }
  }
}
I am using FindControl to find a control inside the ItemTemplate. I then cast DataItem to the item I am binding to the control; a Picture in my case. When the picture is not null I am changing the appearance of the Label by assigning a CssClass. In this example, I am only doing that when the Id is > 5, but clearly this is just an example and you can apply any business logic you see fit.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old June 25th, 2012, 05:11 AM
AnnieCalvert
Guest
 
Posts: n/a
Default

The method of data presentation depends on the number of headers in the grid. Upon display of each row the grid searches for a header for it, and if it doesn't find it, a header from the previous hierarchy level is used. This enables to implement the grid and tree list view in a single component.
http://www.dapfor.com/en/net-suite/net-grid/tutorial
Reply With Quote
  #4 (permalink)  
Old June 25th, 2012, 05:17 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

How does this help the OP? THis is a WinForms grid....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #5 (permalink)  
Old June 25th, 2012, 06:08 AM
Authorized User
Points: 224, Level: 4
Points: 224, Level: 4 Points: 224, Level: 4 Points: 224, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Posts: 41
Thanks: 3
Thanked 4 Times in 3 Posts
Default Thanks Imar !

Thanks for the answer/insight.

I really appreciate the code sample as it provides a great guide ... I'll def attempt to use this in the future ...

- nano
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
General Information Question seananderson ASP.NET 1.0 and 1.1 Basics 4 February 15th, 2007 12:55 PM
General SELECT question rsearing SQL Server 2005 1 January 16th, 2007 12:01 PM
General Question About c++ madeebmir C++ Programming 0 August 15th, 2006 10:48 AM
Very general question merianos VB How-To 4 August 1st, 2006 12:24 PM
General Question stu9820 ASP.NET 1.0 and 1.1 Basics 2 September 23rd, 2003 03:36 PM



All times are GMT -4. The time now is 04:50 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.