I am working on a website and I have some db table called "downloads" where I have files I want users to download. The files are bound to "download type" table.
I know how to display the data from the db on the page, but how do I "split" it so that I have for eg.
download type 1
file 1
file 2
file 3
download type 2
file 1
file 2
file 3
download type 3
file 1
file 2
file 3
... I hope my question is reasonable...
So, the "non-dynamic" way would be to make a datalist for each entry, but what if the user puts one more "donwload type" in the db..?
Any tips are welcome!
Thanks for your time!
You could use a repeater or a GridView to perform this task.
If you have access to LINQ:
Create a LINQ query to get all of the data into a sorted IQueryable object that is sorted by download type. You can then iterate through this list using a repeater or a gridview and each time you come to a new download type, you can output the bolded type before continuing with the next item of data.
If you're stuck using datatables
Get your data down into a datatable and make sure it's sorted by download type. Then you can use the DefaultView of the table to perform filters or with a repeater you can follow similar instructions to above.
Keep in mind, you'll have to use the onDataBound events of these items and keep track of the current downloadtype with a global variable.
This can be accomplished using a GridView with grouping. Unfortunately, the ASP.NET Gridview doesn't make this as easy as it should be. But here is an article about how to do this:
http://aspalliance.com/1268_CodeSnip_How_to_Group_Data_in_the_GridView_Control.all
You can use this technique to bind your data to a Gridview and then Group by the Download Type column.
There are 3rd party products which make this extremely easy, but they aren't always free. One that we use is DevExpress. With their GridView you just tell it which column(s) to group by and you're done. If this is something you need to do routinely or would like to allow you users to do, then it would be worth buying.
Related
I am with a little issue on handling with one of my applications.
I have a Vessel's historic which is shown on a ListView, but until now I have never needed to show all the data inside this history (the user was using kind of a filter to get what he needed), but now one of the managers want to see all data through the application (they was receiving the full data through an excel report).
The biggest issue is because its 6000 rows with 21 columns each one and when I try to select all the data it takes something between 5 minutes to fully load, but more than that the user need to add new, edit or copy the history, which brings him to a new update on the list with more 5 minutes to load.
I don't quite know how is the best way to handle with this and I wanted your help!
I would actually split the information into sections. Rather than loading 6,000 rows plus columns all at once, why don't you use something like alphabetize the information? Use a different ListView for A-G, then another ListView for H-O, then so on and so forth. That why it would cut down the time it took to query all of the information.
So I'm reading data out of a database and want to display it on a webpage like this:
Name Age Fav# ...other info
Bob 11 15
Joe 13 4
I want to make a website that updates the contents of its table based on the database. I know the number of columns that the database has but not necessarily the number of rows.
I was thinking just writing the .aspx file and generating the HTML and values when the database is read, but I was looking at some similar stackoverflow questions and they advise against it? The suggestion was to create a template .aspx file and just populate it, but how would you do that if you don't know the exact number of rows to make?
Also if I programatically write my own Something.aspx files and create a Something.aspx.cs file, will they automatically link together?
I'm new to ASP.net and C#, so I'm not sure if there's an easier way of doing this.
Since you're using ASP.NET I'd suggest using GridView control to display table data. It has a lot more possibilities (like built in paging and sorting). And you do not need to know in advance number of rows - GridView will render whatever is thrown at it, turning on paging if nessesery
I'm working on an ASP.NET page that mutates to the MDB file fed to it. It currently allows you to choose a table to work with, and from there what row to edit, and fills the page with text boxes and fills them with data. This all works but it poses a problem when it isn't a string based field type, for example, what I have a problem with is determining when the cell being targeted is a CheckBoxField type.
My question would be, how can you get the column web control value from a filled GridView?
I think you want your grid to behave somthing like example explained:
http://www.codeproject.com/Articles/37207/Editable-Gridview-with-Textbox-CheckBox-Radio-Butt
Download source code for your refrence.
Hope this will help.
Do you have access to the table? You can try getting the type fron the column collection (table.Columns[name].DataType (from the top of my head)
You can then use the column type to select a control.
I had an interview Question .
Q. how to improve performance of a Gridview contains 100000 Records of data(Datasource might be XML or DB) in c# asp.net ?
I was just blinking as i had no answer for this .Please Give me the solution for this. If possible please give one demo.
No gridview should contain 100000 records.
Your data source may contain 10 times that number of records, it doesn't matter. If you present a user more than 100 records on screen, it would be difficult to work with that data.
Select a datasource that supports paging for the gridview, that way you are only working with the number of records to be displayed on screen.
For a database you can use something like SqlDataSource.
The default XmlDataSource does not support paging, in such cases the grid will have all records in memory and handle paging itself. For xml with large number of records consider using an ObjectDataSource, where you can implement paging yourself.
If you have a choice, always select a data source that supports paging.
To fix such a GridView, I think a good approach would be to:
Add paging (as others have already pointed out)
Add filtering/searching
Add a cap/limit for maximum number of rows shown
The filtering + max limit for results is (in my opinion) a good way to keep the size of the grid manageable. If the max limit is hit using some specified set of filters (=search terms) you could show a message about it to the user and encourage him/her to specify a more specific search if necessary.
As stated before, a gridview should not hold so many rows.
In your interview, they wanted to see if you can say that its bad implemented rather then to check your programming skill.
But if one insist for good performance, I would suggest to use Repeater instead of Gridview.
Cheers,
Ran
I have a editable nested repeater containing the data.I use it for showing the data and also for saving the data which is updated by the user.
I want to detect particular cell/row for which the data has been modified by the user so that I can update only that particular row in the database instead of saving all the data again.
Is there a way to work this out.Which would be the best technique to use ,Javascript or server side code ?
Resource country etc | Week1 Week2 Week3 | Total
ABC XYZ 10 15 20 45
This is the repeater structure.
Middle one (Weeks showing hours worked by resource which is editable) is the nested repeater.
Values can only be changed in the nested repeater.
I maintain unique ID's for each resource in the hidden field.
Can you suggest me some ways to achieve this functionlity ?
This is normally handled by your ORM, but you can implement it yourself if you like. The idea is called 'change tracking', and basically what's commonly done is to retrieve the record from the database, then compare known retrieve values to the new values before saving it again.
Depending on your concurrency strategy, you also might use a hash of the original values that were sent to the client, placed in a hidden field perhaps, which you can then check original vs. currently in the database in order to not accidentally overwrite someone else's changes.