5 Replies - 307 Views - Last Post: 24 August 2017 - 10:51 AM

#1 ikhlas06  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 178
  • Joined: 20-May 16

how to merge two columns in VB gridview?

Posted 24 August 2017 - 09:35 AM

how to merge two columns in VB gridview?


sql query:
Select DISTINCT 
LISTAGG(f.date, ' \n ') WITHIN group (order by m.my_key) as cDate
LISTAGG(f.comment, ' \n ') WITHIN group (order by m.my_key) as DBcomment
From myTable m
...
...



code:
<asp:TemplateField HeaderText="dates" SortExpression="cDate">
	<ItemTemplate>
		<%# Eval("cDate").ToString().Replace("\n", "<br/>")%>
	</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="comments" SortExpression="DBcomment">
	<ItemTemplate>
		<%# Eval("DBcomment").ToString().Replace("\n", "<br/>")%>	
	</ItemTemplate>
</asp:TemplateField>


result:
|----------|----------|
| dates    | comments |  
|----------|----------|
| 1/2/2017 | comment1 |
| 2/4/2017 | comment2 |
|----------|----------|
| 2/4/2017 | comment3 |
|----------|----------|



what I want result to be:
|---------------------|
| date / comment      |  
|---------------------|
| 1/2/2017 - comment1 |
| 2/4/2017 - comment2 |
|---------------------|
| 2/4/2017 - comment3 |
|---------------------|  


Is This A Good Question/Topic? 0
  • +

Replies To: how to merge two columns in VB gridview?

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13488
  • View blog
  • Posts: 53,864
  • Joined: 12-June 08

Re: how to merge two columns in VB gridview?

Posted 24 August 2017 - 09:41 AM

Use your sql query as a subquery.. have that output be your two columns together.
SELECT colA + ' - ' + colB as Foo
FROM
(
    select colA, colB
    from ..     
)

Was This Post Helpful? 0
  • +
  • -

#3 ikhlas06  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 178
  • Joined: 20-May 16

Re: how to merge two columns in VB gridview?

Posted 24 August 2017 - 09:59 AM

is there way to do in gridview?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13488
  • View blog
  • Posts: 53,864
  • Joined: 12-June 08

Re: how to merge two columns in VB gridview?

Posted 24 August 2017 - 10:02 AM

My theory is if you need the data combined you do it in the query as the grid view's job is to just display the data.. not process or take action. Substantially easier, more accurate, and works. You know you can have that combined column AND the individual columns in the same query, right?

In theory you could tweak around in the 'grid bound' event to start making an extra column in the dataset, matching up the data, etc..
Was This Post Helpful? 0
  • +
  • -

#5 ikhlas06  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 178
  • Joined: 20-May 16

Re: how to merge two columns in VB gridview?

Posted 24 August 2017 - 10:11 AM

issue is that my sql query is not as simple as combining two cols. here is my query. I dont think I see how can I colbmine two cols. any ideas?


Select DISTINCT 
...
LISTAGG((case when f.date_update is null then f.sum_date else f.date end), ' \n ') WITHIN group (order by m.my_key) as cDate
LISTAGG(f.comment, ' \n ') WITHIN group (order by m.my_key) as DBcomment
From myTable m
left join (...)...
left join (...)...
left join (...)...
left join (select distinct my_key, date_update, sum_date, date, comment) from fanTable f on f.my_key = m.my_key 
...


This post has been edited by ikhlas06: 24 August 2017 - 10:12 AM

Was This Post Helpful? 0
  • +
  • -

#6 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1829
  • View blog
  • Posts: 5,758
  • Joined: 15-January 14

Re: how to merge two columns in VB gridview?

Posted 24 August 2017 - 10:51 AM

There's a lot of "..." there, but you can always combine or do any other operations on values which you're already retrieving. If you're already retrieving both the date and the comment, then you can do anything with those values in the select list.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1