Loading XML files with different columns into gridview in asp.net - asp.net

I have several xml files which I need to load to a Gridview in asp.net. I load one file at a time (depending on the user's choice of file from a dropdownlist), but each xml file has different fields.
E.g.
XML1 has ID, Image, City, Location, URL.
XML2 has ID, Departure, Destination.
XML3 has ID, Image, Description, Destination, Landmark, URL.
I have 2 more xml files, though, actually. But I think these three are sufficient to show the variety of columns I have in the files.
I tried using the AutoGenerateColumns, which was supposed to be most suitable in this condition, except that I now need to show the images in the Gridview.
So basically I need the Gridview to show data with the columns according to the files. One way is by creating a GridView for each XML, but I am wondering if there's another way to solve this. Partially, since I need to unbind the datagrid and remove the viewstate every time the user changes the dropdownlist selection.
Thanks in advance.

You can use LINQ to XML to join the XMLs on ID column when user makes selection and bind the gridview with the result. http://blogs.msdn.com/b/wriju/archive/2008/03/24/linq-to-xml-join-xml-data.aspx

I've solved this problem but I'm posting the solution I've got so that others can benefit from it.
Here's the link to the solution sample:
http://www.codeproject.com/Articles/13461/how-to-create-columns-dynamically-in-a-grid-view

Related

Pass data between pages ASP.NET

I have two ASP.NET pages.
One of them have a table with some data that came from javascript, each row has a button-link that opens pop-up page. I need to pass the data contained in the selected row to the single row table in pop-up,
what a better way to do that?
If the information are the only identifiers, can move to the other page with parameters in the url, but if they are private or heavy data identifiers is best to store them in the session.
regards

Displaying data with ASP.NET

I have a tbl_categories and a tbl_items. I want to display tbl_categories in a horizontal manner and list objects from tbl_items vertically below each category name. I am confused how to get all this data using TSQL stored procedures and displaying them using ASP.NET native controls.
Columns with headers of category names. rows of items keyed with category_id.
The db is set up correctly. It is the ASP.NET controls I have trouble with.
I would use a Repeater myself, and make it output an HTML Table. The categories row would be in the HeaderTemplate, the closing tags in the FooterTemplate, and the actual data inside the ItemTemplate
http://blogs.sitepoint.com/asp-net-repeater-control/
The best way to handle this is to setup business objects which support the data in a way you wish to present it, which may not always be the way it is handled by your database.
Then you can use those objects directly to bind or feed data into the UI.
You could use Pivot to do that. See this referece http://msdn.microsoft.com/en-us/library/ms177410.aspx

How do I use the ASP.NET grid view to instert new records?

Using the ASP.NET grid view. It displays 3 columns with 1 row for each, displaying an integer saved in the database. I would like to have a text input one for each column, so the user can add a new row of integers to the database. (The table only displays the last row updated, that part seems to be working OK)
Here is the code I have that displays data but without the input option I would like.
What is the way this is done in ASP.NET (3.5)? Are there more options in the control or do I need to manually bring in text input controls and give each one manual code to update the database? Any help is appreciated.
Thank You.
Do you know the asp.net website? There are a lot of tutorials, e.g. about data access. You might find the information you need, e.g An Overview of Inserting, Updating, and Deleting Data.
Also check out the ASP.NET Dynamic Data section on the same page.

Easiest method to build where clause from checked items in DataList of PreviousPage

I have a selection list that is generated dynamically, it lists a number of checkboxes that are based on an end-user editable table, as such I have no idea what data, or how much, might be contained in this table and how many checkboxes or what they might contain, other than the primary keys of the table.
The user will select the checks they wish to see, and then control is passed to another page via PostBackUrl. The second page has to figure out which records to show (build it's where clause) based on the checkboxes checked in the previous page.
So, my problem is several-fold. First, asp:CheckBoxes don't have values. This can be worked around by a number of methods. Right now, i'm using a placeholder and dynamically creating the checkboxes in the ItemDataBound event of the DataList. I set the ID to "CheckboxKey1Key2" (where Key1 and Key2 are the primary keys of the check items).
Second, I have to walk through the controls of the PreviousPage to dig out all these values. That in itself is also a pain, but doable.
Now, my thinking is to build the where clause of my Linq2Sql query based on the keys I got from decoding the checked checkbox names. This all seems like a lot of jumping through hoops for something that shouldn't be this difficult. Am I missing something? Does anyone have any better solutions?
Make a class with a structure for your values that will be useful and easy for you to use on the result page. Then when the user clicks whatever it is they click to go to the result page, loop through the DataList, create a collection from the checked items, and you will only need to grab one object instead of everything, when you need to format your query.
Then when you get to the result page, loop through the collection and build the query in the loop. Pretty easy and not much code.

Convert GridView to Object During Postback

I have a GridView inside of a User Control populated from a List of IObject. I need to get the contents of this GridView so I can export the data to CSV. I was just passing the whole GridView to the procedure and looping through it to get the data I needed. I am using MVP though, and was told this was a bad approach.
I want to convert the GridView back to a List of IObject, and then pass it to the Presenter. Any suggestions besides doing it the brute force way (looping through all columns and rows).
Sounds daft, but why don't you get the data the same way that you originally bind the GridView to?
I recently changed some code that was written the way you describe (I didn't write it)- it actually broke the application as the huge ViewState was too big for a postback (Maximum Request length exceeded)!
I merely extracted the data from the DB, cached it and then got the cached version for the export to CSV (it was actually export to Excel but that's beside the point).
Of course I turned the ViewState on the GridView off, as it was no longer needed.

Resources