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
Related
I am trying to show the sum of totals for different kind of invoices on a web page.
I am using detailsview control, however it does not show all the data in one page. When I enable paging the other types of invoices can be seen on 2nd and 3rd pages.
My SQL command is:
SELECT CARI_HESAP_KODU, FATURA_TURU, SUM(KDV_MATRAHI) AS TUTAR FROM LNX_STD_6_016_01_SLSINVOICES WHERE CARI_HESAP_KODU=#mKodu GROUP BY FATURA_TURU, CARI_HESAP_KODU
When I run it from SQL I get the proper results:
But when I run the page and test detailsview I get:
So I have two questions:
1. Is it possible to show the results as columns (as in SQL view) instead of rows?
2. Is it possible to show all the records in one page?
Thanks in advance.
As stated in the comments by Esko, the details view only shows one record at a time. The details and Grid views are fast easy ways to display data, however if you wanted to customize how data is displayed, a more generic repeater would be the next logical choice, you would just have to do the formatting yourself.
Check out his article or google "asp.net repeater":
https://msdn.microsoft.com/en-us/library/zzx23804(v=vs.85).aspx
When I used to program in web forms a lot, I used repeaters even when a details or grid view would have done the job, because they are much more flexible and easier to maintain when someone asks for changes.
Cheers.
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.
I have a listview in wpf and i am swapping two items index..
the swapping must be visible to the user.
i tried giving thread delay..
it didnt work
How to do that..
If I was going to do this I would delete the list view and lock it up where you can't use it again. Then code whatever your list view was outputting in C# using whatever you use to query your database(I think LINQ to SQL is the most robust solution right now) and then use a string builder to construct the html. This way you can assign a id to each div and append an incrementing number to the end of the id. Finally you could write your javascript and use the id's. Here is a link that shows how to build a gridview without using a gridview control.
See the first answer to the question in this link: How to show pop up menu from database in gridview on each gridview row items?
I am not sure whether it will work for your problem or not.
I think you need some kind of animation there. If it is web project, you can use jQuery animation to do that.
The GridView in ASP.NET when rendered isn't the prettiest or most semantic control ever, is there a way to use <div> using constructing it? Or should there be another approach, I ideally would like to remain using the gridview because I select the DataKeyNames in my code, unless there is a similar way to select the DataKeyNames using another control like a listview?
+1 to Lareau. ListView has a DataKeyNames property as well. I would use Ingrid (jQuery) along with a ListView control to make it better.
ListView samples:
http://weblogs.asp.net/scottgu/archive/2008/01/04/jan-4th-links-asp-net-asp-net-ajax-asp-net-mvc-visual-studio-iis7.aspx
http://basgun.wordpress.com/2007/12/29/listview-control-in-aspnet-35-3/
https://web.archive.org/web/20211020153238/https://www.4guysfromrolla.com/articles/122607-1.aspx
https://web.archive.org/web/20210125144848/http://www.4guysfromrolla.com/articles/021308-1.aspx
Download and demo Ingrid:
http://www.reconstrukt.com/ingrid/
You can use repeater instead
I would go with a listView. Similar to a repeater but just a bit better.
The GridView is tabular data. It uses a table to construct it. It's perfectly semantic. I agree it isn't pretty, but a <div> construction of tabular data is just as ugly. The GridView has the greatest functionality for this kind of data display/management.
You might be able to customize the rendering by overriding the Render method of GridView control. This would mean that you are changing the default behaviour of GridView and might need to handle additional events if you decide to do change defaults.
Instead of using the semantics of a div, I would look to format the class using some tailored CSS. Let me know if this is something you're interested in and I can offer you some links.
I want to make a control that show list of bounded data like in grid view but I want to be able to insert new record from the same control
what is the best asp.net control I can use to do that (GridView , FormView or DetailsView)? and why?
Thanks in Advance
You can do that with all three. If you want to know how, there are some good tutorials on the official ASP.NET website, here.
The choice between them is a formatting/layout decision. A GridView produces a table, showing multiple records, while a DetailsView shows one at a time. A FormView lets you display the data however you want, but required much more effort, since you have to provide the HTML.