Any ideas on how I can acheive 'Hierarchical' gridview?
Basically I want when the user clicks on the '+', i "expand" and insert new rows without a full page post back.
Does this sound like a lot of AJAX stuff? Or should I read on ASP.NET MVC
Please point me in right direction
Another way to do this is the old Grid view inside a Grid view Trick. The basic concept is to have the [+] and the parent data as the Item data in a single templated column. Attach the to click event of the button and set your grid to edit/selected mode. when its in edit mode, render a second grid view with the child data. Although its a gridview inside a gridview, visually it will accomplish a "hierarchical" view.
Sample source code for Hierarchical GridView
with [-] and [+] to collapse and expand as in VB6 Hierarchical Grid
You have two options I suppose:
You can render out those rows you want to insert, and the [+] shows them and hides them
You don't render them out, and they are sent to the browser via AJAX, and then inserted into the table.
I've done it both ways, and the more gridviewy way to do it is the first, in my opinion. You can create a new templatefield for the [+]; define a child relationship name, and then call GetChildRows (or an equivalent) on each row as you render, having those rows render hidden.
#bnkdev - GridView inside a GridView sounds like a total mess.
#Jandwenyi - I suppose you're doing this for a certain scenario and you'll need to reuse it at some point, as unprobable as it may seem now. My suggestion - find a third-party Grid control that would do what you want - there are so many out there.
Related
I manage a project and as you know asp.net has many types of data control, I am confused which control should be used in what condition. Which is better control in what situation. Should I still use repeater control because grid view is advance control.
A repeater allows you to have your items repeated both horizontally and vertically unlike a GridView which only by default repeat the items vertically.
The best way to understand the two is if you need a simple grid displayed use a gridview.
If you need to do additional formatting or display data from the database with additional graphics, labels, not in a grid type form than use a repeater. You can easily adjust the repeater to by as dynamic as you need it to be where as a grid view is a simple grid.
With a repeater you will click on the page SOURCE of the .Cs or .vb file and you will see 4 templates. Anything HTML you put in those templates will repeat with the data.
Around 2010 I ran into so much trouble with the GridView, I asked a (now former) Microsoft evangelist for advice. He strongly recommended not to use the GridView ever. Then I stopped and life got easier.
can someone pls give me a reference about building impressive(or just beautiful ) datagrid \ listview.
all my purpose is to show data (not adding data or editing data).
i have one condition that on click on a specific column data it would reference another page (a detailed view).
i have a list object that contains all the data to bind with it.
thanks in advance
This website has some nice CSS table designs. You could pick one of those, download the appropriate CSS file, include it in the page where you have your table and that should be all.
If all you have is just a simple table, I would recommend you use a GridView rather then a DataGrid, mostly because it's easier to make the GridView render the header/footer sections of the table, which are required for the above CSS files to work. (check this questions for example, How do I get Gridview to render THEAD?)
ListView gives you even more control then a GridView, but you have to type some more code yourself (HeaderTemplate, ItemTemplate, AlternatingItemTemplate, etc). If you have scenarios where you need more control over how the table is rendered the ListView would be better choice, but based on what you said (simple tables) I would recommend the GridView
In VisualStudio, when you drag and drop a table or an individual column from a data connection in server explorer, a gridview is created.
What I want to be able to do is drag and drop the columns to make a quick and dirty detail form to display an individual record. Is this possible in any way?
An even better way to do this would be via a custom T4 or LLBLGen template but I have no clue how to do this.
Any other suggested approaches?
UPDATE: A DetailsView is the type of thing I am looking for, in that you can select a data source and the specific columns you want, but I'd like to be able to have manual control of the layout and formatting after the initial drag and drop.
I suggest binding a DetailsView to the table using a data source (SqlDataSource) instead. You might find these tutorials, especially this one helpful.
In response to your update, have a look at the FormView control. It gives you complete control of the layout using templated sections.
There appears to be literally no way to do this in VS that I have come across.
I am using ASP.Net 2.0. I am using a gridview component over some data because I wanted to get the paging functionality it provides. The rest of my site where I do not need to provide paging because I have used an alphabetical index or because the result set is small enough to fit in the screen I use a repeater. In the repeater I have added the delete shortcut to the end of the table in its own cell. The edit link is provided by clicking on any row in the results and that takes you to a new screen where you can edit the details.
I have not been able to find a way to move the edit and delete columns to the end. Is there perhaps a property that I missed or is the easiest way of doing this going to be extending the Gridview component. If that is the case would it better to extend the component or try and write my own paging functionality to acompany my repeater.
Rather than using the autogenerate delete and edit buttons, you can manually add an edit and delete field using the 'Edit Columns' dialogue from the gridView smart tag. Make sure that Auto Generate fields is not selected and you can then add your columns as desired, and edit, delete and insert are all available as children of the CommandField option.
The best solution of them all would be to get the paging capablilities into your data access solution, so that if you need page 3 you only get those ten records and not the entire list. That way you could also use a repeater to render the list, without having to extend it with paging capabilities - just add another repeater at the bottom that loops out the page numbers as links.
However, if this is not possible, the easiest way would probably be to manually configure the GridView to render the way you want it to (or as close as possible...). It's been a while since I worked with a GridView, but the names I show below are at least close enough for you to find the correct ones with Intellisense in VS.
First, set
AutoGenerateColumns = False
on your GridView. Then, add a <Columns></Columns> section betweeen the <asp:GridView></asp:GridView> tags. Within that section, you should be able to specify each field you want to render, and the order you want them in.
I'm currently building a Gridview that has expandable rows. Each row contains a dynamically created Panel of Form elements. Right now, I have a javascript function that expands (or in my case, makes visible) the panel when an Image is clicked on the Gridview row.
My question is... is there a more efficient way of doing this. Instead of pulling all my data to begin with and building each new row as I Databind, is there a way to simple create the row with the Panel full of textboxes and dropdownlists on the fly when the user clicks the Expand button?"
I'd like to limit the server calls by doing it that way instead of how I'm currently doing it, looping through every row and creating a new panel with form elements and inserting that into a row that is hidden.
Actually, it isn't performing badly since my original SQL query can populate every single row and I have enabled paging on the Gridview. I'm just wondering if they can be built on the fly using PageMethods or some sort of JSON/AJAX solution. I haven't seen anything, but... worth a try in searching for it.
you can override the RowdataBound event, and than add whatever controls you want based on what data goes in the cell.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx
Personally trying to create the data on the fly would most likely result in a slower user experience.
When I do things like what you are describing I typically use Repeaters, that way I can do a template layout that simply defines all of the needed elements right away, and it handles the binding actions.
Otherwise, I would imagine that your way isn't performing too slowly as it is.
Actually worked this recently into an AJAX Handler returning the form structure. It's on demand, and works well. Simply call $ajax via jQuery, return an HTML structure, inject into DIV. It's a bit limiting on actual functionality, so be careful.