Binding Multiple Rows to One DataGrid Column

Hi,

I need to display the content of database columns a, b, c, d in one DataGrid row by inserting break line between them. Columns b, c and d are somethimes empty and I dont want to insert break line if they are empty. Can anyone please help me how to do this...

I have something like this so far.....

Dim Col1 As New BoundColumn

Col1.DataField = ("a") & ("b") ---> it doesnt work...

MyDataGrid.Columns.Add(Col1)

 

Thanks

0
Zumbul
5/10/2005 1:20:45 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

7 Replies
1058 Views

Similar Articles

[PageSpeed] 2

 Zumbul wrote:

I need to display the content of database columns a, b, c, d in one DataGrid row by inserting break line between them

Can u please be more clear on this?? The mapping is not very clear as to displaying columns into 1 row. Did u mean that u wanted to merge the values of all the columns corresponding to each row in your database table into one row??


Shravan Addaypally MCP

0
shravan79
5/10/2005 4:08:31 AM

Database looks like this

Col Col Col1 Col2 Col3 Col4
xData yData a b c d

I want to display it in DataGrid like this

Col_Header Col_Header Col1-4_Header
xData yData a
b
c
d


If Col3 aan Col4 are empty line break shouldn't be inserted.

Does this make it more clear?

Thanks

0
Zumbul
5/10/2005 4:51:16 AM

You could do something like this below.

<asp:BoundColumn HeaderText="xData" DataField="xData"/>

<asp:BoundColumn HeaderText="yData" DataField="yData"/>

<asp:TemplateColumn HeaderText="Col1-4_Header">
     <ItemTemplate>
        <%# DataBinder.Eval(Container.DataItem, "a") %>
        <br>
        <%# DataBinder.Eval(Container.DataItem, "b") %>
        <br>
        <%# DataBinder.Eval(Container.DataItem, "c") %>
        <br>
        <%# DataBinder.Eval(Container.DataItem, "d") %>

      </ItemTemplate>
 </asp:TemplateColumn>

hth


Shravan Addaypally MCP

0
shravan79
5/10/2005 5:37:10 AM
But if the column c and d are empty it will print <br> twice which I don't want.
0
Zumbul
5/10/2005 5:49:28 AM

<asp:TemplateColumn HeaderText="Col1-4_Header">
     <ItemTemplate>

         <asp:Label id="lblStuff" Runat="server"></asp:label>

      </ItemTemplate>
 </asp:TemplateColumn>

In code behind...

DataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{

      // query the table by row and check the values in under field C and field D

      // if they are not empty or not null append their values to the Textproperty of the label within the ItemTemplate of column      

     Label lblstuff = (Label)e.Item.Cells[2].FindControl("lblStuff");

       StringBuilder sb = new StringBuilder();

      sb.Append( row["a"]);

      sb.Append( "<br>" + row["b"]);

      if (row["c"] != "" && row["c"] != System.DBNull)

         sb.Append( "<br>" + row["c"]);

      // same way for row["d"]..

      lblstuff.Text = sb.ToString();       

}

       

 hth  


Shravan Addaypally MCP

0
shravan79
5/10/2005 3:50:23 PM

Thanks a lot.

I managed to do it using sql command with case switch. Performance wise , do you think it is better to do it programmaticaly using code or in sql statement.

0
Zumbul
5/11/2005 12:02:13 AM
What I suggested was using a SQL Statement inside the ItemDataBound event. and include the fields which are present and leave the rest.
Shravan Addaypally MCP

0
shravan79
5/11/2005 1:28:10 AM
Reply:

Similar Artilces:

SQL: mutiple rows one column to multiple columns one row
In InfoMaker SQL can you take a table with multiple rows for the same key and take a column from the rows and create mutiple columns with one report line with the key(no duplicate keys) on a report? For example Table books (key) (book title) 123 misery 123 titanic 123 roots 456 war 456 1984 456 giant The report I need would look like this Key title1 title2 title 3 123 misery titanic roots 456 war 1984 giant Thanks in advance. -- Kaye Hendry HealthInsight email:kaye.hendry@healthinsight.org ...

Can DataGridView control be setup to bind to just one record across multiple rows in the grid?
I have a table that has records that contains groups of date fields (maybe 20 groups of 3 date fields): example schema: LocationID Job# Task1Date1 Task1Date2 Task1Date3 Task2Date1 Task2Date2 Task2Date3 .... and so on for up to 20 Tasks of 3 dates apiece Can I setup a bound DateGridView to show 20(n) rows (based on the 20 groups of tasks on one record) by 3 columns of dates (based on the Task(n)Date1, Task(n)Date2 and Task(n)Date3 fields on the one record) but for just one record at a time? So the grid looks like a 20 row by 3 column, but it is really just one whole record it is sh...

(DATAGRID)How to put 1st column in one row and the rest in the row below?
For example, I want to display a FIELD1,FIELD2,FIELD3,FIELD4 from a table in a datagrid this way: ---------------------------------------------- FIELD1("colspanning it") ---------------------------------------------- FIELD2 | FIELD3 | FIELD4 ---------------------------------------------- FIELD1("colspanning it") ---------------------------------------------- FIELD2 | FIELD3 | FIELD4...

Displaying two rows of database column data in one row of datagrid
Hello, I am trying to display two rows of an access column on one row of datagrid. Is that possible? Example of my intended datagrid: courseNo of course1courseNo of course2 courseNo of course3courseNo of course4 here's the HTML view of my aspx file: <Asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 104px; POSITION: absolute; TOP: 40px"    runat="server" AutoGenerateColumns="False" Height="320px" Width="488px">    <Columns>     <asp:TemplateColumn>      &...

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 ...

Gridview
Hi. What I would like to do is to have a layout like this ID Description SomeOthercolumn ----------------------------------------------------------------------------- ID Short description Text Some other value Long description Text that will span multiple columns ID #2 Short description Text #2 Some other value #2 Long description Text that will span multiple columns #2 Get the picture. This is not a problem with repeaters, because you ha...

Displaying databse query output for multiple rows in one datagrid on another single datagrid
Hi All, I have a datagrid (dg1) from where I select one or more rows simultaneously. When the submit button is clicked, I want to populate another datagrid (dg2) after querying the database for each selected row (based on value in one of the columns in dg1). Is it possible to display the query results for all the selected rows in datagrid 1 (dg1) on a single datagrid (dg2), if I query the database seperately for each row in dg1. Thanks Ankur ...

Binding more then one image to a row in Datagrid
Hi all :), What I managed (with help) to do already is to display in each row of the DataGrid an image which the path is stored in DB. What i am trying to do now is to load (for example) 4 different images in one row. And if there are more images that it goes to 2nd row till 8 images and so on. something like this if there are 10 image paths are loaded from DB: img1   img2   img3   img4 img5   img6   img7   img8 img9   img10   is that possible at all or is it just a dream? any suggestion...

Concatenate multiple rows into one column?
Newbie question here. I have two tables that have a one to many relationship. I want to create a query that takes the info from the child table (possibly multiple rows) and concatenates it into a single column in the parent table. The tables are:TableParent (ASSIGNNUM (PK), DESC, STARTDATE)TableChild (ASSIGNNUM (FK), EMPLOYEENUM)There could be multiple employees for each assignment. Sample data:TableParent1....First Assignment....05/01/20082....Second Assignment...05/03/20083....Third Assignment....05/07/2008TableChild1....553422....334562....523433....352253....451213....11553I would like t...

DataGrid with Multiple rows in one Line
Hi, Is it possible to create a data grid containing only two columns to and it should display three rows across in one line and then next line has three rows and so on. e.g Location Qty Location Qty Location Qty Toronto 10 Mississauga 15 London 12 NewYork 20 Boston 25 NewJersy 25 I have around 70 locations and if I display one row in one line, Users have to do scrolling as this datagrid qty column is in edit mo...

Editing Multiple Rows in DataGrid Control
Hi, i am building a datagrid control n i need to set some of the rows editable while the rest non-editable. i understand tat the edit command only allows a row to be editable anyone time. So there some other ways to go abt it, so as to allow multiple rows editable at anyone time. Please let mi know... Thanx in Advanced!Whoever undertakes to set himself up as a judge in the field of truth and knowledge is shipwrecked by the laughter of gods....

select the row of the datagrid whose value is same as one of the value of row of datagrid
hellow all,  I have a datagrid which is bound to the ordertable,so all the orderdetails are shown on the page load. but my requirement is that,i have a textbox and a search button,when the user enter the order number in the text box and click on the search button the datagrid should show that record whose order number is entered by the user n most imp that the record may be in the 65th or 34th row of the datagrid,i wants to put it in the first row. how to do it. If there's a reason you can't filter down to just the one row, you'll have to come up with some paging algorithm that wil...

SQL,Make Multiple values for multiple columns into one column separated by comma
Hi, I'm getting the result as this Name       Class       Subject------------------------------------------Anju         10             MathsAnju         10             Physics How to write the query to get the result like this Name       Class       Subjects------------...

DataGrid
I have a DataGrid that I am attempting to format as 2 Columns across and 3 Rows per record. In order to do this I'm formatting the DataGrid with 1 ItemTemplate containing a <table> and all of the controls are within this <table>. I would like to be able to alter the contents of some of the output fields (controls) on the fly using the ItemDataBound event. However, when I alter the contents of a cell, all controls are altered with the same value since there is only 1 cell and it contains all of the controls. How can I alter individual controls withing the cell? Than...

Web resources about - Binding Multiple Rows to One DataGrid Column - asp.net.presentation-controls

Code division multiple access - Wikipedia, the free encyclopedia
Code division multiple access ( CDMA ) is a channel access method used by various radio communication technologies. It should not be confused ...

Jakarta attacks: Multiple bombs hit Indonesian capital
ISIS has claimed responsibility for the grenades and crude homemade bombs used to stage a Paris-style attack in a busy business and shopping ...

Sopranos star Jamie-Lynn Sigler has Multiple Sclerosis
... daughter of mobster Tony Soprano on the Emmy-winning drama, has gone public with her struggle with her nearly 15-year battle with multiple sclerosis. ...

Jakarta attacks: seven dead in multiple attacks linked to Islamic State
Jakarta is on highest possible alert for terrorism, after multiple explosions hit Central Jakarta on Thursday.

Jakarta attacks: seven dead in multiple attacks linked to Islamic State
Seven people have been killed in a terrorist attack in central Jakarta, including five who are believed to be perpetrators linked to the Islamic ...

Feature Request: Apple TV 4 needs a way to watch TV shows from multiple sources in one universal app
... coverage of AAPL Company , Apps , and iOS . What do you think? Discuss "Feature Request: Apple TV 4 needs a way to watch TV shows from multiple ...

Google Seeks Multiple Auto Partners for Self-Driving Car Unit
Google hopes to form partnerships with many automakers and suppliers as it develops self-driving cars to reduce traffic accidents and expand ...

Here’s what happens to your eyes when you look at multiple screens
It's more common than ever for people to stare at screens on multiple devices – some at the same time. Here's a tip for what you can do to protect ...

Multiple Explosions, Gunfire Rock Jakarta In Deadly ISIS-Claimed Attack
At least seven people died, including five assailants, a police spokeperson said. Multiple explosions and a gun battle rocked Jakarta, the capital ...

Ramon Foster: Multiple Bengals Spit On Steelers, Not Just Burfict
Steelers OL Ramon Foster joins The Fan Morning Show

Resources last updated: 1/22/2016 3:41:47 AM