Datagrid summary column

A

anon

Hi All,
Perhaps a simple question, but i m unable to get an idea of how to
accomplish this...
i have a customer table and another table which has their details
(maynot be available for all customers)...i would liek to display this
information in a datagrid....with one row for each customer and a
summary column which has the concatenated details field from second
table....i have built the datagrid without the summary column
succesfully...any ideas on how to accomplish this?
thanks for ur time....
Ben
 
S

Scott Mitchell [MVP]

i have a customer table and another table which has their details
(maynot be available for all customers)...i would liek to display this
information in a datagrid....with one row for each customer and a
summary column which has the concatenated details field from second
table....i have built the datagrid without the summary column
succesfully...any ideas on how to accomplish this?
thanks for ur time....

Get all the pertinent dat back in one SQL statement using a JOIN.
Something like:

SELECT C.Name, CD.Detail1, CD.Detail2
FROM Customers C
LEFT JOIN CustomerDetails CD ON
C.CustomerID = CD.CustomerID

Then use a TemplateColumn to display the pertinent fields in the second
column, something like:

<asp:DataGrid ...>
<Columns>
...
<asp:TemplateColumn>
<ItemTemplate>
Details 1:
<%# DataBinder.Eval(Container.DataItem, "Details1") %>
<br />Details 2:
<%# DataBinder.Eval(Container.DataItem, "Details2") %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Happy Programming!

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 
A

anon

hi scott,
that helps, however i donot know before hand how many detail rows are
available for each customer.....some might have 3 rows, some two, some
none...so there is only one field.... detail1...there might be 3 or 2 or
none rows of detail1 for each customerID....like this....
Customer ID Name
1 JOhn
2 Matt
CustomerDetail1
1 value1
1 value2
1 value3
2 value4
2 value5

the datgrid shud display like this:
1 John value1
value2
value3
2 Matt value4
value5

i didnot know clearly if your idea will fit this scenario....please
advice....i greatly appreciate your help...
thanks,
ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,185
Latest member
GluceaReviews

Latest Threads

Top