dynamically populate table in aspx page - c#

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

Related

ListView with 6000 rows c#

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.

Create a Gridview with resizable columns like excel

Please take a look at the screenshot below.
I am trying to create the page with a gridview. The number of column are so many. There are two issues that I am facing here.
1 ) I am using Databale js to provide paging, searching and other facilities. As shown in the screenshot due to large number of columns the search box and paging box are not getting applied on proper place.
2 ) If the column is having a large string , Is there any way we can achieve excel like facility. Where default the overflowed text is hidden and when we click on column to re size it can show the whole value. I am using colresizable plugin for re sizable columns but it is not working as expected.
IdeaSparks ASP.NET CoolControls will work for your problem.

How to improve the performance of a Gridview that contains 10000 data records in c# asp.net?

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

How to implement the following as in the image using asp.net c# GridView

I need to implement the following in the asp.net Gridview. I have the excel sheet as in the image. Based on this image i need to implement data entry application using asp.net gridview.
As you can see in the image from S.NO. 1 TO 5 for every ID Description there are multiple Authors e.g 2,3 or 5. How to implement the same functionality using asp.net gridview so that for every ID Description, user can enter multiple authors while entering the record in the DB design and how to show the records back to gridview as in the excel sheet??
Kindly suggest regarding DB and gridview implementation to handle this?
Thanks
i think you are looking for Nested GridView Control to Display Related Data.See a link. http://msdn.microsoft.com/en-us/library/aa992038%28v=vs.80%29.aspx

C# (ASP.NET) now datalist for each DB entry

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.

Categories