Grouping two columns into one column with GridView

I would like to modify the default output of a gridview to group two columns into one column. This is probably best explained by example. So, lets say there is a simple gridview with the output something like this:

Name           Description                           Date
------------------------------------------------------------------

Foo            Some description of foo        Feb. 7, 2008
Bar            Some description of bar        Feb. 6, 2008

Instead, I would like the output to group the description with the name, and make it look something like:

Name                                                Date
-----------------------------------------------------------------------

Foo                                                Feb. 7, 2008
Desc: Some description of foo
Bar                                                Feb. 6, 2008
Desc: Some description of bar

So, description is still coming from the datasource, its just not in its own column. I've tried extending the GridView class and creating my own custom control. My thought was to override the CreateRow method in order to rearrange how the row itself is created. I think I'm on the right track, but can't quite get there with it.  Can anyone point me in the right direction?

Thanks!

-steve
 



 

-1
slounsbu
2/6/2008 11:51:15 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

6 Replies
4224 Views

Similar Articles

[PageSpeed] 28

Presumably this data is coming from a datasource. Have you considered concatenating the fields in your query instead? Something like:

 

SELECT ProductName + ' ' + 'DESC: ' + ProductDescription, ProductDate
FROM tblProducts
 
"Peace is Every Step." -Thich Nhat Hanh
1
gsdtech
2/7/2008 12:08:12 AM

how about something like this:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">

    <Columns>

        <asp:TemplateField HeaderText="Name">

            <ItemTemplate>

                <%# Eval("Name") %>

                <br />

                <b>Desc: </b><%# Eval("Description") %>

            </ItemTemplate>

        </asp:TemplateField>

        <asp:BoundField DataField="Date" HeaderText="Date" />

    </Columns>

</asp:GridView>


Mike Banavige
~~~~~~~~~~~~
Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
-1
mbanavige
2/7/2008 1:35:16 AM

Well, I feel kinda dumb for not looking into ItemTemplates a bit more. This seems like it will solve my problem and I'll try it tomorrow at work to confirm. Sorry, its my first project with ASP.NET and maybe I got a little carried away Embarrassed I'll mark as answered tomorrow when I confirm this is what I need.

Thanks again!

0
slounsbu
2/7/2008 1:50:09 AM

No need to apologize.  We all need to get started somewhere. Hopefully that markup will be what you were looking for.

and...

Welcome to the community!


Mike Banavige
~~~~~~~~~~~~
Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
2/7/2008 2:02:34 AM

Thanks for the help and the welcome :) Okay, so that worked for the most part. Now its showing something like this:

 Name                                       Description                               Date
--------------------------------------------------------------------------------------------------------------------

Foo                                            Some description of foo               Feb. 7, 2008
Desc: Some description of foo
Bar                                             Some description of bar              Feb. 6, 2008
Desc: Some description of bar

 The description column still shows up. So, how do I get rid of that? As a more generic question, how do I tell a GridView to not show a specific column from a datasource?

Thanks again!

-steve

 

0
slounsbu
2/8/2008 3:39:59 PM

 Okay, nevermind. AutoGenerateColumns was set to True which is obviously the issue. Thanks again!

-1
slounsbu
2/8/2008 4:08:47 PM
Reply:

Similar Artilces:

how to split the content of one column in the objectdatasource into two parts and let them display in two columns in the GridView?
i combine the title and the body of one article and store it in one column in the database,but i want to show the title and body seperately in the GridView,how should i achieve this goal?thank you so much for your advice!!! you can write the logic of splitting the column into two (title and body) in the query itself by which you are filling the datasource..Thanx, [KaushaL] || BloG || Profile || Microsoft MVP"I would love to change the world, but they won’t give me the source code"Don't forget to click "Mark as Answer" on the post that helped you.This credits that me...

How to manipulate images and combe multiple database columns into one column in a GridView control
Hi Folks,I'm hoping someone can help me out with something.I am trying to put together a photo album as a learning exercise and have a GridView control with two columns linked to an Access Data Source. In the left hand column (called Image) I want to display the photo and in the right hand column (called Details) I want to provide details such as Date, Location, People and Comments, Camera Type etc. Each of these is columns is taken from the database I have set up.However, I have am having some problems:1: At the moment I have been able to get the image to display (using an image column ...

Comparing one column group value to another column group
Hi there, I'm trying to get the difference between two values that are in seperate column groups:   Class Session 1 Class Session 2   Math Score Math Score Diff from class 1 Student 1 75 70 -5 Student 2 75 90 +15  In other words, I want to subract the math score of class session 1(column group1) from the math score of class session 2(column group 2) and place that value in a new column that resides within column group two.  I have a bootleg way of getting the column to show up for column groups that are not first, but I have no idea h...

Combine Two Different Columns into one column
Hi Guys,   I have twotables(Employee and Borrower). In Employee table have EMPID and Borrower table have BorrowerID. I want to comebine these two columns into one column as EMPID  in Employee table. Can  any one help? Thanks what is realtion between to tables ?   Use    Union Thanks for reply. Acutally Employee table EMPID, NAME Columns. in this Employee table had 12000 rows. Borrower table has BorrowerID,BType etc.. .Here Employee ID and BorrowerID both are same. This table has 16000 rows. Now my what i want to do is Come EMPID and BorrowerID and ...

Disable button server control under GridView when one of the Column in Gridview Total is Zero
Hi web page(aspx) consist of a GridView with two columns displayed from Database. GridView has two columns 1)Employees_Department and 2)Total_Employees. In Employees_Department column employee department name is retrieved and displayed as a Hyperlink when Total_Employees column value is not Zero(This is achieved using row_databound event code shown below). Clicking or selecting particular Employees_Department row will open data for that Employees_Department in a new window. In Total_Employees column of the GridView, total number of employees in that(row) department displayed. GridView is ...

Only one table column in n-columns presentation style
Hi all, I think it�s better to explain our problem with an example. Any idea to do this data (2 records): ID: 1 DATE: 19/01/2000 OBS: 11111111111 22222222222 333333 aaaaaaaa line444ae q qwe qweqee ID: 2 DATE: 19/01/2000 OBS: ad asdasda as fffffffffff hhhhhhh mmmmmmmmmPPPPPPPPPP ooooo on one DataObject (something) like: ************ ID: 1 DATE: 19/01/2000 OBS: 111111111111 aaaaaaaa 444ae 22222222222 q qwe qweqee 333333 ************ ID: 2 DATE: 19/01/2000 OBS: ad asdasda as PPPPPPPPPP ...

appending data from one column to another column in gridview
 Hi,I have 2 columns in table..like this,Area    Areaunit100       sq.feet200       sq.yard400        meters  While showing area in gridview, i want to append its unit . Example 400 meters should be seen and not just 400<asp:BoundField DataField="area" HeaderText="AREA" SortExpression="area" />  Please Mark the post as "ANSWER" if it helps you One way is using template field, check this code..  <asp:TemplateField HeaderText="AREA"> <It...

two db table column, one datagrid column
Dear all, I have a db table which have two column, first name and last name. Can I show them in one datagrid column? Thanks Yes you may. Through the usage of the TemplateColumn, yes. An example of this: <code> <asp:DataGrid runat="server" ID="dgSomeGrid">     <Columns>         <asp:TemplateColumn>             <ItemTemplate>                 <%# DataBinder.Eval(Container.DataSource, "LastName") %&g...

Merge two text columns into one text column
Hi Everyone.. I would like to know what is the best way to merge two text column into one test column in the table. Thanks pbj ANY HELP PLS.. Are you using any front end application or unix or just the isql to merge two text datatype columns? If you are using any front end application then it should not be a problem to merge the two text datatype columns. ...

Dividing one column to 4 columns in the Repeater control
Hi Folks, The following is my Repeater-Control code that providing a list of 20 companies names. I'm getting all of the data in one long column and I would like to divide this one column to 4 columns. Is it possible? how can I do it in my code: <asp:Repeater ID="catlist" runat="server"> <HeaderTemplate> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> ...

SQL query to one column od database into two columns
Hi,I have a empskill Table which has 3 Columns (1) EmpID (2) SkillTypeID and (3) CourseID.Now  SkillTypeID column has data 1 or 2 .......in here 1 means Primary Skill and 2 means Secondary Skill. CourseID will reflect the ID's of subjects like c#,SQL,etc I need a Query which will count the number of primary skilled and number of secondary skilled persons based on subject and will display as followsCOURSE ID      SKILL TYPE  21                        222  &n...

Display multiple columns in Gridview from One Column of SQL table
Hi I have a table in sql with 2 columns and I want to display that in multiple columns in Gridview. SQL Table No.            Type 1               A1 1               B2 2              A2 2               B2 3        &...

How we can change control from one column to specific column in datawindow
How we can change control from one column to specific column in datawindow programatically. Let's suppoose there are three column in datawindow 1: Name 2: address 3: Phone when we open the window, Tab or Cursor is on column 1 (Name) now i have one button ...i want to write code in that button...when i click that button control or tab or cursor goto the phone column. Please somebody tell me how i can do this... thanks noaman mughal SetColumn. -- Bruce Armstrong [TeamSybase] http://www.teamsybase.com Two new books on developing with PowerBuilder http://www.pb9...

When is a column not a column?
I have several extremely similar datawindows that I have to maintain that go against the same table. Recently, I had to add a column to that table, and also add the column to ALL of these datawindows that go against this table. I added the column to the first datawindow, set up the edit control style, etc. I then did a copy/paste of the columns edit control to the remaining dw's (of course remembering to first add the column in SQL). Everything (update props, column specs, column props) seems to indicate that the pasted column is linked to the column I selected, HOWEVER, when I...

Web resources about - Grouping two columns into one column with GridView - asp.net.presentation-controls

European Grouping of Territorial Cooperation - Wikipedia, the free encyclopedia
An EGTC must have members from at least two member states and members can include local or regional authorities, bodies "governed by public law ...

SnapRecall 3D - Photo Sphere with Time Grouping on the App Store on iTunes
Get SnapRecall 3D - Photo Sphere with Time Grouping on the App Store. See screenshots and ratings, and read customer reviews.

Google Not Grouping Results? - Flickr - Photo Sharing!
More at www.seroundtable.com/archives/016794.html

YouTube - Windows 8: Semantic Zoom and Grouping Apps
Veröffentlicht am 05.04.2012 CIO.com's Shane O'Neill shows you how to zoom in and out to get a better view of your apps, and how to group multiple ...

Anachronistic UN electoral groupings need an overhaul
Anachronistic UN electoral groupings need an overhaul

Wanderers v Al Hilal: Tony Popovic praises his nervous players for re-grouping during ACL final
THIS is a final only halfway done, and the body language of the two coaches betrayed the tension still to be played out before the winner is ...

Let's give it a chance, says business grouping
Let's give it a chance, says business grouping

How to Hang a Perfect Wall Grouping (or Frame Cluster)
Bring out the hammer and start with the anchor piece. Hang on one side, then the other, then again and again, while keeping a sharp eye on balance. ...

Reeder for iOS updated with improved navigation, grouping by feed & multiple bug fixes
... left/right to go forward and back. A loading progress indicator has also been added to the in-app browser. Smart streams now support grouping ...

Reeder 2 Update Brings Feed Grouping, Themes And More
... and Fever. Soon after its release, it was also chosen as our AppAdvice App of the Week . Reeder 2 Reeder 2 Update Brings Feed Grouping, Themes ...

Resources last updated: 1/20/2016 8:12:30 PM