I can't seem to find a good answer for this. I'm trying to set up a webpage to grab data from a database and display it something like:
username1
image1.jpg
imagename
image2.jpg
imagename2
username2
image3.jpg
imagename3
username3
image4.jpg
imagename4
image5.jpg
imagename5
image6.jpg
imagename6
There is a username, and with that username there is one or more images and image names. Not all the usernames will have the same number of images.
My question is, what is the best way to do this? I am able to accomplish this using a repeater control with a nested repeater. It's messy but works.
From what I've read, a ListView should be able to do the same thing but much cleaner. My problem with a ListView is that I have to set the GroupItemCount, it's not dynamic like i need. I think I can nest another ListView, but it turns out to be as much code as using a repeater.
Is one of these methods (repeater or listview) preferred over the other. Or is there a better way to do this that i'm not thinking of? I don't think that what i'm trying to do is out of the ordinary, so I think there would be a quicker way. To me, it seems much easier to do this in classic asp using for loops.
Thanks in advance for any input.
The GroupTemplate is instantiated when a certain number (GroupItemCount) of ItemTemplate are instantiated. The ItemTemplate is called for each object in the collection and you first have a collection of users. Even if you can change the GroupItemCount during the ItemDataBound event, this will reflect how the next group of users is created. There is nothing about images until now, so I can say that you can't use ListView for a such task.
Using a repeater inside the ItemTemplate of the main Repeater (or ListView if you want) is the best choice, also common, so you don't have to worry about the mess, another developer will easily see your intention.
Related
I'm pretty new to c#, the first thing that I'm trying to make is a ListView with data bindings which has turned out ok.
I'm now trying to make items have a twist button if the underlying model has any children (like the TreeView). Each of the children will have columns the same as all the top level items.
How would I go about doing this? Is there an already existing control like this? If not would I be better off dressing up a TreeView to look like a ListView, or dress up a ListView to look like a TreeView?
I went down the road outlined in this solution which dresses up a TreeView, but the end result looks pretty awful and the heading is actually just an item, so you lose all the nice column sizing and column buttons that can hook up to column sorting that you get in ListView so that route actually seems like it would be more work.
I noticed the new task manager has a control exactly like what I'm trying to create, I don't know how this made? probably in C though.
Microsoft provides a sample that appears to be what you are looking for. A write-up of the example can be found here:
http://msdn.microsoft.com/en-us/library/vstudio/ms771523(v=vs.90).aspx
When you build and run the example you will end up with something resembling this:
There is a large amount of templating done in the example, so you will be able to make things look the way you want.
What you describe sounds a bit like a TreeListView, and if you google 'WPF TreeListView' you will see some solutions that might be good for you. I have used one from Telerik, but it might be overkill depending on how complicated your needs are.
If you only want one sub-level like the image you attached, you might want to just roll your own using a ListView with a complex DataTemplate for the first column which would show an expander button and a simple ListBox bound to the children items.
Similar to the answer here, except your cell would have a checkbox styled to look like the arrow, the text for the item, and a child ListBox. Then bind the visibility of the child ListBox to the state of the checkbox.
So my question is this, I have a gridview that filters data from a database when a search keyword is entered. The problem is, that I need it to show some 20 different fields, which is significantly too long for a web page. The gridview goes beyond my asp.net webpage width and off of it. I was wondering if there was any way I could make it neater and easier to read, or fit all the data fields on one page. I'm not too familiar with this, so excuse my lack of know-how in and thank you in advanced.
A few suggestions:
Show fewer fields.
Make your columns really narrow.
Make your grid a header row only (contains only minimal info for a record). Clicking a link in a row will display further details for that item.
Use a DataList, Repeater or ListView so you can layout the row yourself.
You can try something like this:
http://weblogs.asp.net/dwahlin/archive/2007/07/31/freeze-asp-net-gridview-headers-by-creating-client-side-extenders.aspx
I think this thread on another site addresses exactly what you're asking:
http://forums.asp.net/t/1277793.aspx/1
I'm watching at this page:
http://leeontech.wordpress.com/2010/02/01/summary-row-in-datagrid/
But they're using silverlight. I'm trying to create that user control to use it in a WPF C# application. I mean, not using Silverlight. But I can't find the namespaces: GroupHeader
I'm having a hard time with this. Thanks in advance.
Okay listen, you can totally do this, and in some scenarios I even recommend it.
Using a CollectionViewSource you can easily group your data. In the HeaderTemplate you can even use an Expander (or make your own) and get the animation you might be wanting. Here's a link to a sample of this: http://jerrytech.blogspot.com/2010/06/wpf-data-presentation-step-by-step.html
Using an ItemsControl, you can easily present your groups and details. In the ItemTemplate you can use styles make this look like a grid (if that is really what you want). You can also shift the style based on the type if your collection has more than one type of object in it (eat that datagrid!).
You can wire up your column headers (which will really be custom objects, right?) and handle all the sorting and stuff like that. They will look just right! Not like datagrid WinForm column headers!
Here's what's hard (not impossible, but more coding).
User-resizable columns.
User-rearrangable columns.
New record using bottom, empty row.
Paste from Excel (doesn't work right in datagrid either).
Select Row, highlight Column header.
That's it.
In lots of situations, this is really nice.
For the most part, I cannot stand the datagrid. Too restricting on UX.
I don't think you're not going to be able to get a silverlight control working in WPF.
Adding a footer row to the WPF datagrid is something a lot of people have complained about; it's ridiculous that it wasn't included out of the box.
See this thread from MSDN
Having been through this myself, your best bet will probably be to bite the bullet and use a third party control. It sucks, I know.
My web page will get a set of results from the database and display it to the user. However I am not sure about "number" of results.
Each result will have a panel which contains several controls in itself, an image, several labels, etc.
What is the best way to do this dynamically, eg. create these controls dynamically?
Is it better to use an AJAX control? Should I use Gridview?
Thanks for the help,
Behrouz
You need to give us more details about how each result will look like.
I would being by looking at a repeater control. You don't need to know the number of results that get passed to it. You'll be able to specify a template for how each result will look like and the repeater control will take care of rendering one for each result.
A repeater is probably the better option for that scenario.
Add all the controls you're likely to need and switch them on and off as needed via the item databound event.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemdatabound.aspx
If the template for each item is the same, use a Repeater. Bind via AJAX if you'd rather bind via web services and save on server-side performance. Then you have to manage everything on the client, which can be tedious, but very performant. Use JQuery to make it easier.
Server-side adding of controls can be a pain, but doable.
HTH.
I want my ListBox to have columns, and one of those columns have to be a clickable URL.
How can I achieve this?
You can't do it in a ListBox. You can create your own control, or settle for another existing one. Based on the question, I'd guess you're not yet at the stage where you're creating your own controls. That takes a pretty good understanding of existing controls and the way they work under the covers (but a google search for creating Winforms Controls should yield plenty of instructions.) Edit added It looks like te 4th and 5th links in combination on that google search should get you what you need. You can create your own user control and then do an array of them)
As far as for other possible alternatives, have you considered a DataGridView? A DataGridView can have a hyperlink and it can have checkbox columns, so this would be one possible alternative.
Here's a link for having a Hyperlink column in a DataGridView.
Well, it is possible by using the CustomTabOffsets property (unreliable) or the DrawItem event. And implementing the MouseDown event to find out if that particular 'column' was clicked.
But there's little point, a ListView control with View = Details gives you the same functionality.