Display rows in multiple columns in Asp.net Gridview - asp.net

By default each row of a Gridview maps to each row in a datatable or dataset attached to its datasource. But what if I want to display these rows in multiple columns. For example if it has 10 rows, 5 rows each should be displayed in 2 columns side by side. Also can I do this with the Infragistics grid. Is this possible?

You can use a DataList control instead. It has a RepeatColumns property that you can define the number of columns you want to display.
In .NET Framework 3.5, there is an even better solution, the ListView control. You can find further information about how to use the ListView control here.

If this is a pure coding exercise, then bind to the RowDataBound event of the Gridview. That way, you can do:
e.Row.Cells(2).Text = e.Row.Cells(1).Text
This would place the text from column 1 in column 2 after it has been pulled from the database. You can also dynamically create columns using a similar method.
Re-reading, I think I misunderstand your problem though.

Can't you just put two identical bound columns one after the other?

Related

How I can add checked rows from grid view to another girdview in asp.net c#

I have two GridViews. The first grid view's first column is a checkbox.
How can I populate a second grid with the values of the checked rows from the first grid?
For this you need to have a for loop for taking all the rows together and one after another you need to check for the checkbox check property and for all those which are checked you need to add them into another dataset and then you have to assign that dataset to another grid.
You can find detailed narrative here,
http://www.aspsnippets.com/Articles/Transfer-Selected-Rows-from-one-GridView-to-Another-in-Asp.net.aspx

Showing multiple records on the same row in Gridview

May I know how to show multiple records on the same row in Gridview?
the purpose of these enumerable data bound controls is to show one record/row/object per item template. If you want to show multiple records/rows/objects you will need an intermediate step to aggregate the individual record/row/object together.
then you could bind to the gridview. however, i would recommend the ListView so you can customize the layout however you like.

How do I add columns and rows dynamically to an asp.net 1.1?

I am working on an ASP.NET 1.1 project where the requirement is to create a matrix table where the number of rows and the number of columns are determined by two separate datasets and can vary. Once the matrix is created the page has several buttons that do postbacks that need the data and any modifications made to a cell in the matrix table to be retained.
The <asp:DataGrid />is the obvious option but how do I add columns dynamically to the control?
I am also considering dynamically building <asp:table /> control on the fly but I am not really sure if this is the way to go.
A problem I have with datagrids is that they blindly bind to a dataset. The table I am creating has the first column as the sum and the second one as the weighted average of the subsequent column data. There is also a grouping of the columns.
In this scenario is it better to use a table server control and build the entire thing or do this in a datagrid ?
you can programatically add columns to a datagrid like that :
BoundColumn linkColumn = new BoundColumn();
linkColumn.DataField = "UserID";
linkColumn.DataFormatString = "<a href='UserDetails.aspx={0}'>User Details</a>";
linkColumn.HeaderText = "User Details";
DataGrid1.Columns.Add(linkColumn);
programmatically adding rows is adding rows to datasource that you bind to datagrid, isn't it ?
In my opinion using grid is simpler, grid manages binding and formatting for you. But using table gives you ability to manage cells to you.
Not sure what is the bottleneck. It is possible to retain values in dataset using viewstate or session.
You can create a instance of a column and what you need and add to data grid.Check google for samples instead of posting here,on google you would find sample of how to work with a data grid.Data grid is better.

How do I manually add additional rows to the bottom of an ASP.NET gridview?

I have a situation where I'm populating a gridview with a bound data source, and want two additional rows at the very bottom; one to show the sum of values in the columns and one to show the average of values in the columns. I can quite easily calculate these values by aggregating information taken from the rowDataBound event, but don't know how to go about manually adding the additional two rows to the gridview. Any help much appreciated.
You can use the Footer just like you use Headers in gridview. Another solution is use a query in such way:
query 1 : your original query
UNION
query 2 : your query which contains sum
(This applies only if you don't apply paging to your grid)
If it's a single row of information you can use summary footer. See Displaying Summary Information in the GridView's Footer.
(source: asp.net)
If you want two additional rows, you can stuff rows into an IList. At the business logic layer, you can add more rows to the list returned by DAL.

how do I create an array or list of ASP.NET checkboxlists

I know how to use the checkboxlist in ASP.NET to display options retrieved from a database. What I don't know how to do is to make this 2-dimensional. That is, I need a list of checkboxlists where I don't know how long the list is; both dimensions of the checkboxlist will be determined by
list of people (pulled from database)
list of tasks (pulled from database)
and the user of the web page will click in column/row to specify which people will be assigned which tasks.
Right now I'm thinking that my only option is to brute-force it by creating a table and populate each cell with its own checkbox. (yuck)
Is there a more elegant way to create a 2-dimensional array of checkboxes with labels for both rows and columns?
I would use a repeater along with a checkboxlist. Depending on how your database is setup you could have each checkboxlist databound.
I've done this before and resorted to the brute-force method you suggest.
It's not as nasty as you'd think. Other solutions that were declarative and databound would likely be just as convoluted and confusing.
I use the ASPxGridView from DevExpress. It has a control column type of Selected (or something like that) which will display a checkbox in the column with the other column populated from your bound datasource. The User can select any rows desired by checking the checkbox on the row and you can get all the selected rows easily inot a collection to process. DevExpress components really do get rid of a lot of brute-force programming.
You can programmitaclly use a GridView control. It's inherently two-dimensional and you can use databound CheckBoxFields for it.
If you're looking for a quick and dirty way, you can use the AJAX Control Toolkit with the two controls and can populate one based on the other. If that's not what you're looking for, I'd do it the brute force way.

Resources